Introduction to Docker Containers

Share the page with

Creating a container

When we call

docker container run

It performs two tasks:

We can create container by

docker container create

We can start container by

docker container start

When we create container from an image, we can specify its configuration. It means we can specify the evironment variables, arguments, name, etc.

Understanding the command run command:

docker container run --rm -it ubuntu:latest /bin/bash

Container configuration

Name

To give a container name use

docker container create --name="my-cool-container" ubuntu:latest

Labels

Lables are keyvalue pairs in Dockerfile (image).

We can specify label by using option flag -l or --label.

docker container run --rm -d --name="container-with-label" \
-l deployer=Vikas -l tester=Vikas \
ubuntu:latest

Hostname

By default the hostname is same as the container id.

We can set the hostname by

docker container run --rm --it \
--hostname="mycontainer" ubuntu:latest /bin/bash

Domain Name Server

TODO

Storage volumes

When the default disk space allocated to a container is not appropriate for the job at hand, In these cases we need storage that can persist between container deployments.

In such case we use --mount or -v option. For example,

docker container run --rm --it \
--mount=type=bind,target=/mnt/session_data,source=/data \
ubuntu:latest /bin/bash

You can read more about the bind mount here.

Share the page with