Introduction to docker

Matthew 2021-01-21 16:01:08
introduction docker

introduction Docker, What do you want to download ? Register what ?

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 .

  • register DaoCloud account number , Get acceleration services ! Undeniable? , Sometimes directly from Docker Official to local pull The image will be very slow ... At this time, we can go through the domestic Docker Service providers get free acceleration pull Image services , Alibaba Netease seems to have this kind of service , I chose DaoCloud: Click me to register DaoCloud account number

Login after registration DaoCloud, Find this button

next , Follow its steps , Add... To yourself Docker Accelerated Service

  • This is the end of the preparatory work , Go to the next part !

To get started Docker, First you need to understand Docker!

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 :

  • One , It's a mirror image (Image), The image is static 、 Files that can be shared by users . People we've played with both systems and virtual machines know , First you need a .iso Mirror image , To install the system .Docker The mirror image in is also this thing , The image is static , You can't operate on him , Can only pull Someone else's mirror image or push My own mirror image .
  • One more , It's a container (Container), As I said before , The image is static and inoperable , Can only be shared and downloaded , So what can be operated ? It's in the container ! The container can be understood as the dynamic state of the image , That is, the state of the system installed in our virtual machine , In fact, it's not right to say so , The best description of a container should be Linux Of iso Of documents Live CD Pattern , For example, when we play dual systems, we have all entered Live CD Pattern , 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 CD The 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 .
  • Last , It's a warehouse. (Repository). You see what I wrote earlier pull and push What? , Have you fainted ? I don't know about you git Familiar with not familiar with ,Docker The warehouse in is very similar to git Code warehouse for , You can pull Before myself push Image to your own warehouse to local , It's fine too pull others push Mirror to the public warehouse to your own place . To put it bluntly, baidu cloud disk , You can upload (push) Make your own environment Docker Up , You can also download (pull) Mirror your own cloud to the local . meanwhile , We know that the biggest feature of Baidu cloud is sharing ( You know, hey, hey, hey ), analogy Docker, If you get Baidu cloud share link ( Other people's mirror names 、 Tags and other people's user names ), You can also download (pull) Others share the image to their own local , Others can download (pull) Your image , because Docker The warehouses are all public . Of course , Each free user has a quota to set their own image as private , That is, it's forbidden to be shared with others , Analogy Baidu cloud you save and have not been generated to share the link of the little sister .

Next, let's take a concept map of a tall building , Let's have a look 2333

Next is the actual combat

Open your iTerm2!( Open normal terminal It's OK , This does not affect )

  • see Docker Version information
 The input terminal :
docker version

My version information displayed

 ~$ docker version
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 All Rights Reserved)

But I don't usually need that much information , So what I've been using is docker -v command

  • It is time to pull Your first mirror image

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
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 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 ...
latest: Pulling from
aed158d74952: Pull complete
773ae8273d14: Pull complete
d1d487w88782: Pull complete
cd3d6cd6c0cf: Pull complete
8d73bu79120c: Pull complete
Digest: sha256:35bc48a1ca97c3f74rhf378hj92hd82j29i4hf4hf84nf0dhnsid232de8d8
Status: Downloaded newer image for

The command you enter is actually equivalent to docker pull command , From the registration server 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 .

  • Check your local image warehouse !

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 16.04 e4415b714b62 11 days ago 128.1 MB latest e4415b714b62 11 days ago 128.1 MB 12.04 aefa163f7a7e 11 days ago 103.5 MB 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 :

  • From which warehouse , such as ubuntu
  • The mark of the mirror , such as 16.04
  • its ID Number ( only ), such as e4415b714b62
  • Creation time
  • Image size

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 .

  • Start your image and install the software !

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

-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

  • Want to exit the container ? It's simple !

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
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
  • The software is installed , Want to save the environment ?commit To help you !

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
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 All Rights Reserved)

utilize exit Exit the container . here Docker There are two containers in the engine , You can use docker ps -a see .

  • Want to delete the container or the image ? Use this !

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 .

  • Attached is a picture of Docker Command chart

  • A configuration , Use everywhere ? It would be push To hub Come on.

Because it was already there 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 了 !

Docker Install in gcc、gdb Problems encountered in

  • add-apt-repository: command not found

14.04 System solutions :

apt-get install software-properties-common

older Version of the system :

apt-get install python-software-properties
  • Docker Use in gdb Unable to enter breakpoint , Unable to debug

add --privileged Parameters

~$ 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 .


  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云