Skip to content

Docker Deep Dive: Creating Containers

Tanveer Alam edited this page Jun 11, 2019 · 1 revision

docker container run --help | more

$ docker container run busybox
$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
881b6fa2acf4        busybox             "sh"                9 seconds ago       Exited (0) 6 seconds ago                        friendly_meitner
$ docker container prune -f

--rm - to delete container once exited

$ docker container run --rm busybox
$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Runs in foreground

$ docker container run nginx
^C

-d - to detach from foreground and run as background process

$ docker container run -d nginx
9129fa4a00945ba1c240128e8a61f69beca8c56c1c82f2fcef2b64f346201080

-it - i keeps the the STDIN open and t allocates pseudo-TTYto the container

$ docker container run -it busybox
/ # 
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ #

We can even make changes inside the container and take a snapshot(docker container export) and import using (docker container import)

--name - Set name of the container

$ docker container run --name my_busybox busybox
$ docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                          PORTS               NAMES
e95239654852        busybox             "sh"                     10 seconds ago      Exited (0) 7 seconds ago                            my_busybox

Additional flags:

-p, --publish list - Publish container's port to the host

-vm --volume list - Mount a volume(the bind type of volume)

--mount mount - Attach a filesystem to the container

--network string - Connect a container to a network(default "default")

Container's World



Clone this wiki locally