systemctl start docker docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:e18f0a777aefabe047a671ab3ec3eed05414477c951ab1a6f352a06974245fe7 Status: Downloaded newer image for hello-world:latest
Hello from Docker! This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit: https://docs.docker.com/get-started/
cd /path/to/app touch Dockerfile # add the following contents to the Dockerfile: FROM node:12-alpine RUN apk add --no-cache python2 g++ make WORKDIR /app COPY . . RUN yarn install --production CMD ["node", "src/index.js"] EXPOSE 3000
cd /path/to/app docker build -t getting-started . #Build the container image
Start
1 2
docker run -dp 3000:3000 getting-started # After a few seconds, open your web browser to http://localhost:3000.
Docker常用命令
帮助命令
1 2 3
docker version # 显示docker的版本信息 docker info docker --help
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 13 months ago 13.3kB node 12-alpine 00881b4ed7f5 19 months ago 88.9MB
REPOSITORY 镜像仓库源 TAG 标签 IMAGE ID id CREATED 创建时间 SIZE 大小
docker images --help
[root@localhost /]# docker images --help
Usage: docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Options: -a, --all Show all images (default hides intermediate images) --digests Show digests -f, --filter filter Filter output based on conditions provided --format string Pretty-print images using a Go template --no-trunc Don't truncate output -q, --quiet Only show image IDs
[root@localhost /]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql MySQL is a widely used, open-source relation… 13424 [OK] mariadb MariaDB Server is a high performing open sou… 5118 [OK] phpmyadmin phpMyAdmin - A web interface for MySQL and M… 673 [OK] percona Percona Server is a fork of the MySQL relati… 592 [OK] bitnami/mysql Bitnami MySQL Docker Image 78 [OK] databack/mysql-backup Back up mysql databases to... anywhere! 74 linuxserver/mysql-workbench 45 ubuntu/mysql MySQL open source fast, stable, multi-thread… 38 linuxserver/mysql A Mysql container, brought to you by LinuxSe… 37 circleci/mysql MySQL is a widely used, open-source relation… 28 google/mysql MySQL server for Google Compute Engine 21 [OK] rapidfort/mysql RapidFort optimized, hardened image for MySQL 13 bitnami/mysqld-exporter 4 ibmcom/mysql-s390x Docker image for mysql-s390x 2 newrelic/mysql-plugin New Relic Plugin for monitoring MySQL databa… 1 [OK] vitess/mysqlctld vitess/mysqlctld 1 [OK] hashicorp/mysql-portworx-demo 0 docksal/mysql MySQL service images for Docksal - https://d… 0 rapidfort/mysql8-ib RapidFort optimized, hardened image for MySQ… 0 mirantis/mysql 0 cimg/mysql 0 drud/mysql 0 silintl/mysql-backup-restore Simple docker image to perform mysql backups… 0 [OK] corpusops/mysql https://github.com/corpusops/docker-images/ 0 drud/mysql-local-57 ddev mysql local container 0
docker pull mysql #下载镜像 docker pull mysql:5.7 #指定版本
删除镜像
1 2 3 4 5 6 7 8 9 10
docker rmi -f $(docker images -aq) [root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest feb5d9fea6a5 13 months ago 13.3kB node 12-alpine 00881b4ed7f5 19 months ago 88.9MB mysql latest 8457e9155715 20 months ago 546MB [root@localhost /]# docker rmi -f feb5d9fea6a5 Untagged: hello-world:latest Untagged: hello-world@sha256:e18f0a777aefabe047a671ab3ec3eed05414477c951ab1a6f352a06974245fe7 Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412
容器命令
容器以镜像为基础运行
下载一个centos镜像
1
docker pull centos
启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
docker run [可选参数] image #参数 --name = "Name" 容器名字 -d 后台方式 -it 交互式运行 -p 制动端口 主机端口:容器端口 -P 随机指定端口 # 启动、进入容器 [root@localhost /]# docker run -it centos /bin/bash [root@33ecabd1756c /]# ls bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var [root@33ecabd1756c /]# exit #退出 exit