docker的安装就不罗嗦了,随便找几条命令执行下就OK了。今天要说的是镜像的拉取,容器的建立及在容器中安装想要的软件。我在这个过程中遇到的问题也记录了下来。
1.镜像的拉取
我拉取的是ubuntu基础镜像: docker pull ubuntu
遇到了报错:
Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
原来是docker服务没开启,只需执行命令 :systemctl restart docker
然后再执行: docker pull ubuntu
[root@192 admin]# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
2746a4a261c9: Pull complete
4c1d20cdee96: Pull complete
0d3160e1d0de: Pull complete
c8e37668deea: Pull complete
Digest: sha256:250cc6f3f3ffc5cdaa9d8f4946ac79821aafb4d3afc93928f0de9336eba21aa4
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest
拉取完成,执行 docker images 命令来查看我们的镜像
[root@192 admin]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 549b9b86cb8d 6 days ago 64.2MB
hello-world latest fce289e99eb9 11 months ago 1.84kB
2.镜像有了,那就通过 IMAGE ID 来创建容器
[root@192 admin]# docker run -it 549b9b86cb8d bash
root@5aefcabecf97:/#
看出两行的不同吗? 对,@后的内容变了。5aefcabecf97 是容器 ID,以后我们就通过这个ID来进入这个容器。
接下来我们退出容器:root@5aefcabecf97:/# exit
查下我们所创建的容器:docker ps -a (-a表示所有的容器,不加的话显示的是未退出(关闭)的容器)
重新进入该容器:
[root@192 admin]# docker exec -it 5aefcabecf97 bash
Error response from daemon: Container 5aefcabecf97f8b7a09b43f72efbd38cf70695ac253c741881687c042c61ea11 is not running
说什么该容器没运行!
那就先开启吧:docker start 5aefcabecf97
[root@192 admin]# docker exec -it 5aefcabecf97 bash
root@5aefcabecf97:/#
进来了!
3.在容器中安装我们心仪的工具
我们就以编辑神器-------vim为例吧
首先,更新下工具:apt-get update
root@5aefcabecf97:/etc/apt# apt-get update
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB]
Get:3 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [6781 B]
Get:4 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [761 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB]
Get:8 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [19.2 kB]
Get:9 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [795 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB]
Get:12 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB]
Get:13 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [1322 kB]
Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [10.5 kB]
Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [1057 kB]
Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [32.7 kB]
Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [4244 B]
Get:18 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2496 B]
Fetched 17.4 MB in 12s (1472 kB/s)
Reading package lists... Done
现在就可以安装了
root@5aefcabecf97:/# apt-get install vim
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
file libexpat1 libgpm2 libmagic-mgc libmagic1 libmpdec2 libpython3.6
libpython3.6-minimal libpython3.6-stdlib libreadline7 libsqlite3-0 libssl1.1
mime-support readline-common vim-common vim-runtime xxd xz-utils
Suggested packages:
gpm readline-doc ctags vim-doc vim-scripts
The following NEW packages will be installed:
file libexpat1 libgpm2 libmagic-mgc libmagic1 libmpdec2 libpython3.6
libpython3.6-minimal libpython3.6-stdlib libreadline7 libsqlite3-0 libssl1.1
mime-support readline-common vim vim-common vim-runtime xxd xz-utils
0 upgraded, 19 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.9 MB of archives.
After this operation, 61.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]
系统会提醒你要装的依赖,直接键入Y就行了!
装完就可以测试下了
root@5aefcabecf97:/etc/apt# vim sources.list
没问题的!!!
root@5aefcabecf97:/etc/apt# python3
bash: python3: command not found
我擦,还没安装python,不说了,我要去安装了,拜拜~~