The Ultimate Guide to Docker (3)

Super, incredibly easy step-by-step instructions

first step

Install Docker .

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:

Interesting link:

Useful items and links

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326481936&siteId=291194637