您好,登录后才能下订单哦!
这篇文章主要讲解了“Docker的基本操作方法有哪些”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Docker的基本操作方法有哪些”吧!
root@jaking-virtual-machine:~# apt-get install -y docker-engineReading package lists... Done Building dependency tree Reading state information... Done ... root@jaking-virtual-machine:~# docker versionClient: Version: 18.06.1-ce API version: 1.38 Go version: go1.10.4 Git commit: e68fc7a Built: Fri Oct 19 19:43:14 2018 OS/Arch: linux/amd64 Experimental: falseServer: Engine: Version: 18.06.1-ce API version: 1.38 (minimum version 1.12) Go version: go1.10.4 Git commit: e68fc7a Built: Thu Sep 27 02:39:50 2018 OS/Arch: linux/amd64 Experimental: falseroot@jaking-virtual-machine:~# systemctl start dockerroot@jaking-virtual-machine:~# systemctl enable dockerSynchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable docker
搜索ubuntu相关的容器
root@jaking-virtual-machine:~# docker search ubuntuNAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys… 8838 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 247 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 184 [OK] consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session… 136 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 95 [OK] ubuntu-upstart Upstart is an event-based replacement for th… 92 [OK]
root@jaking-virtual-machine:~# docker pull ubuntu-upstartUsing default tag: latest latest: Pulling from library/ubuntu-upstart 8387d9ff0016: Pull complete 3b52deaaf0ed: Pull complete 4bd501fad6de: Pull complete a3ed95caeb02: Pull complete a6dc1658c730: Pull complete 9ed623dca71b: Pull complete 998ee72febf9: Pull complete 437038dc2fba: Pull complete da0ee05a1a1d: Pull complete 1e1c3e99deb1: Pull complete 4fcc22d7b2a1: Pull complete 6c7dda5571e4: Pull complete Digest: sha256:597dfb1868012dcd04a705572dbc1542cb7598bce0eaa1c2656eb3acfc8b51d2 Status: Downloaded newer image for ubuntu-upstart:latest
root@jaking-virtual-machine:~# docker images ubuntu-upstartREPOSITORY TAG IMAGE ID CREATED SIZE ubuntu-upstart latest b28219773b9b 2 years ago 253MB
从上面的结果可以看到,容器已经成功下载。利用下载的ubuntu-upstart容器,可以运行一个简单的程序,此处以“Hello Docker”为例:
root@jaking-virtual-machine:~# docker run ubuntu-upstart /bin/echo Hello DockerHello Docker
还可以使用其他容器,如使用ubuntu作为容器,下载操作如下:
root@jaking-virtual-machine:~# docker pull ubuntuUsing default tag: latest latest: Pulling from library/ubuntu 32802c0cfa4d: Pull complete da1315cffa03: Pull complete fa83472a3562: Pull complete f85999a86bef: Pull complete Digest: sha256:6d0e0c26489e33f5a6f0020edface2727db9489744ecc9b4f50c7fa671f23c49 Status: Downloaded newer image for ubuntu:latest root@jaking-virtual-machine:~# docker images ubuntuREPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 93fd78260bd1 10 days ago 86.2MB
当Docker中包含了容器,就如同虚拟机中安装了操作系统一样,可以运行、安装软件、做一些设置。现在就可以运行之前下载的ubuntu:
root@jaking-virtual-machine:~# docker run -i -t ubuntu /bin/bash#运行一个名为ubuntu的容器#i选项表示捕获标准输入和输出;t选项表示分配的终端和控制台root@05559b460591:/#root@05559b460591:/# uname -aLinux 05559b460591 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linuxroot@05559b460591:/# exit#退出容器exitroot@jaking-virtual-machine:~# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
命令可以看到使用run命令运行了一个容器但退出之后容器也关闭了这不是想要的结果-这时可以使用选项d让容器一直在后台运行” data-source-line=”114″>从上面的命令可以看到,使用run命令运行了一个容器,但退出之后容器也关闭了,这不是想要的结果。这时可以使用选项d让容器一直在后台运行:
root@jaking-virtual-machine:~# docker run -d -i -t ubuntu /bin/bashb19cc95aef9cb6f402062915b527864cf045debc65dbabd23a495cea32a138dd root@jaking-virtual-machine:~# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b19cc95aef9c ubuntu "/bin/bash" 15 seconds ago Up 14 seconds kind_johnson 05559b460591 ubuntu "/bin/bash" 35 minutes ago Exited (0) 9 minutes ago xenodochial_hypatia 5bc78fd29b2a ubuntu-upstart "/bin/echo Hello Doc…" 42 minutes ago Exited (0) 42 minutes ago silly_jennings c54bb6d664b7 ubuntu-upstart "/bin/echo Hello Doc…" 44 minutes ago Exited (0) 44 minutes ago jolly_thompson
从上面的命令输出可以看到一个ID为b19cc95aef9c的容器正在运行,这个ID号就是操作此容器的重要参数。 容器运行在后台时,可以使用attach登录正在运行的容器:
root@jaking-virtual-machine:~# docker attach b19cc95aef9croot@b19cc95aef9c:/# exitexitroot@jaking-virtual-machine:~#
容器的操作还有很多命令,常用的操作还有:
docker cp :将容器中的文件复制到主机上 docker rm:删除一个容器 docker port:配置容器的端口转发 docker start:启动一个容器 docker stop:停止一个容器 docker top:显示容器中的进程 docker ps:列出容器 docker logs:获取容器的日志 除了以上这些操作外,Docker还有许多操作,可自行阅读相关文档了解。
感谢各位的阅读,以上就是“Docker的基本操作方法有哪些”的内容了,经过本文的学习后,相信大家对Docker的基本操作方法有哪些这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。