Loading

Quipoin Menu

Learn • Practice • Grow

docker / Running Containers
tutorial

Running Containers

Now that you have an image, you can run containers from it. This chapter dives deeper into the docker run command and how to control container behavior.

Basic Container Run

The simplest form:
docker run my-python-app
This creates a container from the image, runs the default command, and then stops the container.

Running in the Background (Detached)

For long‑running applications like web servers, use the -d flag to run in detached mode:
docker run -d --name my-nginx nginx
The container runs in the background, and you get a container ID printed.

Interactive Mode

To run a container and interact with its shell:
docker run -it ubuntu bash
You'll get a bash prompt inside the container. Type exit to leave.

Publishing Ports

To access a container from your host, map a host port to the container port:
docker run -d -p 8080:80 nginx
Now you can open http://localhost:8080 to see Nginx.

Setting Environment Variables

Pass environment variables with -e or --env:
docker run -e MY_VAR=hello alpine env

Mounting Volumes

To persist data or share files between host and container, use volumes or bind mounts:
docker run -v /host/path:/container/path myapp
We'll cover volumes in detail later.

Container Naming

Give your container a name for easier management:
docker run -d --name webserver nginx


Two Minute Drill
  • docker run creates and starts a container.
  • -d runs in background; -it for interactive.
  • -p host:container publishes ports.
  • -e sets environment variables.
  • --name assigns a custom name.

Need more clarification?

Drop us an email at career@quipoinfotech.com