Super, incredibly easy step-by-step instructions
first step
The Docker command tool requires root privileges to work. You can put your user in the docker group to avoid having to use sudo every time.
second step
Download an image from the public registry with the following command :
$> docker pull ubuntu:latest ubuntu:latest:The image you are pulling has been verified 3b363fd9d7da:Pull complete .....<bunch of downloading-stuff output>.....8eaa4ff06b53:Pull complete Status:Downloaded newer image for ubuntu:latest $>
This public registry has mirrors for almost everything you need: Ubuntu, Fedora, Postgresql, MySQL, Jenkins, Elasticsearch, Redis, and more. The Docker developers maintain several images in this public registry, but you can pull a large number of self-built images from user releases from it.
Maybe you need or want a private registry (for developing applications like containers), you can look at this first . Now , there are several ways to set up your own private registry . You can also buy one .
third step
List your mirrors:
$> docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest 8eaa4ff06b534 days ago 192.7 MB
the fourth step
Create a container from this image.
$> docker run --rm -ti ubuntu /bin/bash root@4638a40c2fbb:/# ls bin boot dev etc home lib lib64 media mnt opt proc root...... root@4638a40c2fbb:/#exit
A brief description of the previous command:
- --rm: Tell Docker to remove the container as soon as the running process exits. This is very useful when testing and saves clutter
- -ti: Tell Docker to allocate a pseudo-terminal and enter interactive mode. This will go inside the container, useful for rapid prototyping or experimentation, but don't turn on these flags in a production container
- ubuntu: this is the image the container is based on
- /bin/bash: the command to run, since we started in interactive mode, it will display a prompt for the container
When running the run command, you can specify the link, volume, port, window name (if you don't provide it, Docker will assign a default name), etc.
Now, we run a container in the background:
$> docker run -d ubuntu ping 8.8.8.831c68e9c09a0d632caae40debe13da3d6e612364198e2ef21f842762df4f987f $>
The output is the assigned ID, since it's random, yours will be different. Let's check if the container is up:
$> docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31c68e9c09a0 ubuntu:latest "ping 8.8.8.8"2 minutes ago Up2 minutes loving_mcclintock
Right there, it was automatically assigned a name called loving_mcclintock . Let's see what's going on inside the container:
$> docker exec-ti loving_mcclintock /bin/bash root@31c68e9c09a0 :/# ps - aux | grep ping root 10.00.06504636?Ss20:460:00 ping 8.8.8.8 root@31c68e9c09a0:/#exit
What we do is run the program inside the container, here the program is /bin/bash. The -ti flag does the same thing as docker run, placing us in the container's console.
end
That's about it. There is so much to say, but that is beyond the scope of this article.
However, I will provide some links and further readings that I think are very important or interesting.
The basic structure of Docker:
Further reading:
- Dockerfiles : allows you to define images using a text file, this is very important
- Did I say dockerfiles are very important?
- You should really take a look at dockerfiles
- docker build : you need this to build your dockerfiles
- docker push/docker pull
- docker create/docker run
- docker rm/docker rmi
- docker start/docker stop
- docker exec
- docker inspect
- docker tag
- Links
- Volumes
Interesting link:
- ANNOUNCING DOCKER MACHINE, SWARM, AND COMPOSE FOR ORCHESTRATING DISTRIBUTED APPS
- Docker at Shopify: How we built containers that power over 100,000 online shops
- Why CoreOS is a game-changer in the data center and cloud
- Docker Misconceptions
- Microservices - Not a Free Lunch!
- Feature Preview: Docker-Based Development Environments
- How to compile Docker on Windows (thanks to computermedic on reddit )
Useful items and links