The force :
Docker allows you to run applications inside containers.
Running an application inside a container takes a single command:
$ docker run
A first exercice will
launch a bash commande line (/bin/echo ‘hello dockerworld’)
on a linux ubuntu image (ubuntu:14.04)
inside our in a container (docker run)
$ docker run ubuntu:14.04 /bin/echo 'Hello world'
During this execution, Docker will look for the ubuntu:14.04 image in your Docker host.
If Docker doesn’t find it, he looks for it on the public part of Docker Hub and download it in your Docker host.
To learn more about docker images : see the post about Managing Docker Images
As soon as the command echo ended, the docker container stop.
A second exercice will
launch a bash session
let the container alive until you quit the bash
$ docker run -t -i ubuntu:14.04 /bin/bash
you can try somme commands : pwd, ls, ..etc
until you exscute exit commande line , you will use the session on the docker container
A third exercice will
launch a container as a deamon (which we ll be more helpful !!)
present you « container ID »
show you the docker ps
command to show the containers who are running
show you the docker logs
command to show what happen inside a container
$ docker run -d ubuntu:14.04 /bin/sh -c "while true; do echo hello world; sleep 1; done"
this will give you a container id which is a unique identifier of your container
$ docker ps
this will show all the running containers and give you
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
the NAME is automatically given by docker command. it will help you to work on your container
exemple :
$ docker logs xxxxxxxxxx
where xxxxxxxxxx is your CONTAINER NAME
This will give the standard output of your container
hello world
hello world
hello world
hello world
To stop the container : $ docker stop xxxxxxxxxxxx