1. Running a container with Podman

To start a new container and interactively run a shell in it, run the command:

podman run --rm -it $(image_name) bash

Note that the flag --rm removes the container once it is stopped. The flag --it runs the container interactively, allowing for user interaction.

 

2. Executing commands in a container with Podman

A. Using podman run

We can run commands inside the container by first opening a shell in the container with the command:

podman run --rm -it --entrypoint bash $(image_name) 

Once inside the container's shell, you can execute any desired commands as you would in a regular terminal.

Alternatively, you can specify the commands you wish to run with the command:

podman run --rm -it --entrypoint $(commands_we_want_to_run) $(image_name)

 

B. Using podman exec

Commands can be run in existing containers with the command:

podman exec -it $(container_name) bash

The command podman ps can be used to get the names of running containers.

3. Bind Mounting with Podman

Bind mounting in Podman allows you to share files and directories between the host system and containers. To bind mount a host directory to a container path, run:

podman run -v $(host_path):$(container_path) --rm $(image_name)

To mount a file or directory as read only, run:

podman run -v $(host_path):$(container_path):ro --rm $(image_name)