Docker Install well , After the account is registered , Click... On the top bar of the desktop Docker Icon , Click on sign in, Log in to your Docker account number .
Login after registration DaoCloud, Find this button
next , Follow its steps , Add... To yourself Docker Accelerated Service
I'm not bullshit anymore , I'm right Docker The understanding of the ：
Docker, It can be said to be a terminal command line virtual machine , But more accurately , It should be a virtual environment . such as , You want to be in PC On seamless use Linux Well ？ So virtual machines are not your only way , Do you have Docker！ I prefer to weigh Docker For a container , Of course, it's just Docker A narrow interpretation of ,Docker It's more than just a container .Docker contain 3 An important concept ：
Live CDPattern , For example, when we play dual systems, we have all entered
Live CDPattern , Enter the system directly without installing the system , It's amazing, isn't it ,Docker That's the concept of a container , It's just lighter, faster and more convenient . however
Live CDThe harm is that you make changes after the shutdown of the installed software all gg, The same goes for containers , Once launched directly , Previously installed gcc ah vim Ah, everything gg fall . If you want to save changes , You need to encapsulate the current container as a new image , So the next time you start the new image, the changes you made before are still in .
Next, let's take a concept map of a tall building , Let's have a look 2333
Open your iTerm2！（ Open normal terminal It's OK , This does not affect ）
The input terminal ： docker version
My version information displayed
~$ docker version Client: Version: 17.06.2-ce API version: 1.30 Go version: go1.8.3 Git commit: cec0b72 Built: Tue Sep 5 20:12:06 2017 OS/Arch: darwin/amd64 ... //omitted by sgy(Copyright http://blog.csdn.net/s_gy_zetrov. All Rights Reserved) ...
But I don't usually need that much information , So what I've been using is
docker -v command
Docker After installation, it will not bring its own image , You need to get yourself from the warehouse pull A mirror image down , It's also a reason to make your own image , You can create your own image based on the existing image or read this blog : How to create yourself at random Docker Mirror the resulting tutorial Docker Mirror officials seem to offer only Linux, It's easy to think ,windows and mac I have to pay for it ？
Search for ubuntu Of Docker Mirror image
docker search ubuntu, Well, if you want something centos, Just change it , It doesn't distinguish between writing , My return result ：
~$ docker search ubuntu NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 6636 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 131 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 105 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 86 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 80 [OK] neurodebian NeuroDebian provides neuroscience research... 40 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 31 [OK] ... //omitted by sgy(Copyright http://blog.csdn.net/s_gy_zetrov. All Rights Reserved) ...
Take the latest version of the official ubuntu Mirror image ：
docker pull ubuntu:latest, Among them latest It's a label （tag）, Indicates the latest version . The information you should get , Something like that
～$ docker pull ubuntu:latest Trying to pull repository docker.io/library/ubuntu ... latest: Pulling from docker.io/library/ubuntu aed158d74952: Pull complete 773ae8273d14: Pull complete d1d487w88782: Pull complete cd3d6cd6c0cf: Pull complete 8d73bu79120c: Pull complete Digest: sha256:35bc48a1ca97c3f74rhf378hj92hd82j29i4hf4hf84nf0dhnsid232de8d8 Status: Downloaded newer image for docker.io/ubuntu:latest
The command you enter is actually equivalent to
docker pull registry.hub.docker.com/ubuntu:latest command , From the registration server
registry.hub.docker.com The called
ubuntu The download tag is
latest Mirror image .
Because of my lab Uniform requirements ,ubuntu need 14.04 edition , So I am hub There's a search in there , Found a user to share 14.04 64 Bit pure image （base image）, Now take his mirror off
~$ docker pull chug/ubuntu14.04x64
This user has many other versions of ubuntu System ,12 13 14 Of 32 position 64 There are , It's all pure images .
After pulling down the initial image , You can start it , however , You can use it first
docker images Command to view your own local image , I picked up a random example , Yours should be like this ：
~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/ubuntu 16.04 e4415b714b62 11 days ago 128.1 MB docker.io/ubuntu latest e4415b714b62 11 days ago 128.1 MB docker.io/ubuntu 12.04 aefa163f7a7e 11 days ago 103.5 MB docker.io/centos latest 0584b3d2cf6d 3 weeks ago 196.5 MB
Find the following statement from an online tutorial , Better than I said , Let's see this ！
In the list of messages , You can see several fields of information :
The mirror image of ID It uniquely identifies the image , be aware ubuntu:16.04 and ubuntu:latest Have the same image ID , That they are actually the same image . TAG Information is used to mark different images from the same warehouse . for example ubuntu There are multiple images in the warehouse , adopt TAG Information to differentiate between releases , for example 10.04 、 12.04 、 12.10 、 13.04 、 14.04 etc. . For example, you can use
docker run -t -i ubuntu:16.04 /bin/bash The command specifies to use the image
ubuntu:16.04 To start a container . If you don't specify a specific marker , It is used by default
latest Tag information .
The following contents are based on myself pull Coming down chug For example, the initial image of ：
Now you have an initial image , Notice that there is nothing in this , even vim Not even loaded , It's a mirror image that can't be reduced any more .
Start it first ：
~$ docker run -it chug/ubuntu14.04x64 /bin/bash root@aa97ba3292ce:/#
-it Indicates running in interactive mode , yes -i -t Abbreviation , namely -it Two parameters ：-i and -t. The former means open and hold stdout, The latter means to assign a terminal （pseudo-tty） In general, this mode can be activated bash, Then there is command line interaction with the container
You can see that the prefix of our terminal becomes
root@aa97ba3292ce:/# 了 , This means that our image has created a container instance . Now we can talk about this “ubuntu System ” It's working
Such as installation vim：
root@aa97ba3292ce:/# apt-get install vim Reading package lists... Done Building dependency tree... Done The following extra packages will be installed: file libexpat1 libffi6 libgpm2 libmagic1 libpython2.7 libpython2.7-minimal libpython2.7-stdlib libsqlite3-0 libssl1.0.0 mime-support vim-common vim-runtime Suggested packages: gpm ctags vim-doc vim-scripts The following NEW packages will be installed: file libexpat1 libffi6 libgpm2 libmagic1 libpython2.7 libpython2.7-minimal libpython2.7-stdlib libsqlite3-0 libssl1.0.0 mime-support vim vim-common vim-runtime 0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded. Need to get 10.7 MB of archives. After this operation, 50.7 MB of additional disk space will be used. Do you want to continue? [Y/n]
It's no use seeing me sudo, Because it's already a super user （root） Status quo .
In the same way, according to my own needs , I installed. gcc and gdb
If you use exit, Command exit , Then the state of the container is Exit, Instead of running in the background . If you want to keep the container running , Rather than stop , You can use shortcut keys ctrl+p ctrl+q sign out , The state of the container is Up.
View the currently running container ：
~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES aa97ba3292ce chug/ubuntu14.04x64 "/bin/bash" 7 minutes ago Up 7 minutes relaxed_hoover
See there's one right now ID by aa97ba3292ce The container of . start-up 、 stop it 、 Restart container aa97ba3292ce The order of ：
~$ docker start aa97ba3292ce ~$ docker stop aa97ba3292ce ~$ docker restart aa97ba3292ce
After starting a container in the background , If you want to get into this container , have access to attach command ：
~$ docker attach aa97ba3292ce
Turn the container into a mirror image , The perform commit operation , Use... When finished
docker images see
root@aa97ba3292ce:/#exit // Exit the container first ~$ docker commit -m "ubuntu with vim" -a "sgy" aa97ba3292ce sgy/ubuntu:vim ~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE sgy/ubuntu vim 52166e4475ed 5 seconds ago 358.1 MB chug/ubuntu14.04x64 latest 0584b3d2cf6d 9 days ago 196.5 MB
among ,-m Specify description information ;-a Specify user information ;aa97ba3292ce For the container id;sgy/ubuntu:vim Specify the user name of the target image 、 Warehouse name and tag Information . I'm just making up my user name for my blog , My own user name is not sgy, You use your own registration when you run the command Docker The user name of .
here Docker There is our new image in sgy/ubuntu:vim, This image and the original ubuntu The difference between images is that there are more vim Tools . At this point we use the container created by the new image , Bring it with you vim 了 .
Start the newly created image , You can see vim I've brought it with me .
~$ docker run -it sgy/ubuntu:vim /bin/bash root@520afc596c51:/# vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 4 2017 18:14:54) ... //omitted by sgy(Copyright http://blog.csdn.net/s_gy_zetrov. All Rights Reserved) ...
utilize exit Exit the container . here Docker There are two containers in the engine , You can use
docker ps -a see .
If you want to delete a container or image , have access to rm command , Be careful ： Before deleting the image, you must first delete the container based on the image （ Even if it's a stopped container ）, Otherwise, the image cannot be deleted , Will report a mistake
Failed to remove image (e4415b714b62): Error response from daemon: conflict: unable to delete e4415b714b62 (cannot be forced) - image has dependent child images Like this .
~$ docker rm container_id ~$ docker rmi image_id
Sometimes even if you delete all the containers , The image still cannot be deleted , Click here mac In the top bar docker logo, choice restart, then try again rmi, There should be no problem .
Because it was already there Docker.app Log in to Docker account number , So now directly
~$ docker push sgy/ubuntu:vim
That's all right. ！ Next time I get to the computer room , stay ubuntu Installation in system Docker, Configure the accelerator , start-up Docker,
docker login Log in to your account , And then directly
~$ docker pull sgy/ubuntu:vim You can push To hub The image of the configured environment is stripped down . Finish the experiment , Again push Just go up ok 了 ！
14.04 System solutions ：
apt-get install software-properties-common
older Version of the system ：
apt-get install python-software-properties
~$ docker run -it --privileged sgy/ubuntu:vim /bin/bash
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .