一、下载及启动:
1、docker 启动
2、docker 删除
ubuntu中docker彻底卸载 - 饭米雪 - 博客园网上很多博主提供的命令行,其实并不能完全卸载docker。。。 #删除某软件及其安装时自动安装的所有包 sudo apt-get autoremove docker docker-ce docker-https://www.cnblogs.com/fmixue/p/15789202.html
二、常见操作:
1image
1.1 获取和列出镜像
# 获取镜像命令格式:docker pull [选项] [Docker Registry 地址[:端口号]/]仓库名[:标签]$ docker pull ubuntu:18.04
18.04: Pulling from library/ubuntu
92dc2a97ff99: Pull complete
be13a9d27eb8: Pull complete
c8299583700a: Pull complete
Digest: sha256:4bc3ae6596938cb0d9e5ac51a1152ec9dcac2a1c50829c74abd9c4361e321b26
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04# 运行查看
$ docker run -it --rm ubuntu:18.04 bashroot@e7009c6ce357:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic# 列出镜像
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 5f515359c7f8 5 days ago 183 MB
nginx latest 05a60462f8ba 5 days ago 181 MB
mongo 3.2 fe9198c04d62 5 days ago 342 MB
<none> <none> 00285df0df87 5 days ago 342 MB
ubuntu 18.04 329ed837d508 3 days ago 63.3MB
ubuntu bionic 329ed837d508 3 days ago 63.3MB
1.2 删除和上传镜像
1.3 dockerfile
1.4 image 其他操作
2 container
2.1 查看容器:
docker ps -a
docker container ls
(base) user@ubuntu:~$ docker ps --helpUsage: docker ps [OPTIONS]List containersOptions:-a, --all Show all containers (default shows just running)-f, --filter filter Filter output based on conditions provided--format string Pretty-print containers using a Go template-n, --last int Show n last created containers (includes all states) (default -1)-l, --latest Show the latest created container (includes all states)--no-trunc Don't truncate output-q, --quiet Only display container IDs-s, --size Display total file sizes
2.2 创建及删除容器
(base) user@ubuntu:~$ docker run --helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]Run a command in a new containerOptions:--add-host list Add a custom host-to-IP mapping (host:ip)-a, --attach list Attach to STDIN, STDOUT or STDERR--blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)--blkio-weight-device list Block IO weight (relative device weight)
2.2.1 常用创建命令
# docker run 命令格式:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]$ docker run ubuntu:18.04 /bin/echo 'Hello world'
Hello world$ docker run -t -i ubuntu:18.04 /bin/bash
root@af8bae53bdd3:/## -i 交互使用,-t 显示容器运行终端。常常连在一起使用:-it
2.2.2 启动,终止,重启和删除容器容器
docker container start container_name # 启动容器docker container stop container_name # 终止容器docker container restart container_name # 重启容器docker container rm container_name # 删除容器# container_name :容器名
2.2.3 进/出容器
docker exec -it container_name docker attach container_name # 在容器stdin中exit,退出容器后会终止容器# 退出时如果想继续运行:按顺序按【ctrl+p】,【ctrl+q】
# 如果不想继续运行:按【ctrl+d】或输入exit
2.2.4 导出导入容器 : (待续ing)
2.2. 5 容器重命名等其他命令
(base) user@ubuntu:~$ docker container --helpUsage: docker container COMMANDManage containersCommands:attach Attach local standard input, output, and error streams to a running containercommit Create a new image from a container's changescp Copy files/folders between a container and the local filesystemcreate Create a new containerdiff Inspect changes to files or directories on a container's filesystemexec Run a command in a running containerexport Export a container's filesystem as a tar archiveinspect Display detailed information on one or more containerskill Kill one or more running containerslogs Fetch the logs of a containerls List containerspause Pause all processes within one or more containersport List port mappings or a specific mapping for the containerprune Remove all stopped containersrename Rename a containerrestart Restart one or more containersrm Remove one or more containersrun Run a command in a new containerstart Start one or more stopped containersstats Display a live stream of container(s) resource usage statisticsstop Stop one or more running containerstop Display the running processes of a containerunpause Unpause all processes within one or more containersupdate Update configuration of one or more containerswait Block until one or more containers stop, then print their exit codes
3
参考资料:前言 - Docker —— 从入门到实践
9Ubuntu Docker 安装 | 菜鸟教程Ubuntu Docker 安装 Docker Engine-Community 支持以下的 Ubuntu 版本: Xenial 16.04 (LTS) Bionic 18.04 (LTS) Cosmic 18.10 Disco 19.04 其他更新的版本…… Docker Engine - Community 支持上 x86_64(或 amd64)armhf,arm64,s390x (IBM Z),和 ppc64le(IBM..https://www.runoob.com/docker/ubuntu-docker-install.htmlUbuntu Docker 安装 Docker Engine-Community 支持以下的 Ubuntu 版本: Xenial 16.04 (LTS) Bionic 18.04 (LTS) Cosmic 18.10 Disco 19.04 其他更新的版本…… Docker Engine - Community 支持上 x86_64(或 amd64)armhf,arm64,s390x (IBM Z),和 ppc64le(IBM..https://www.runoob.com/docker/ubuntu-docker-install.htmlUbuntu Docker 安装 Docker Engine-Community 支持以下的 Ubuntu 版本: Xenial 16.04 (LTS) Bionic 18.04 (LTS) Cosmic 18.10 Disco 19.04 其他更新的版本…… Docker Engine - Community 支持上 x86_64(或 amd64)armhf,arm64,s390x (IBM Z),和 ppc64le(IBM..https://www.runoob.com/docker/ubuntu-docker-install.html