docker是提供給開發或管理人員的容器化部署項目工具php
#先更新yum yum update; #設置docker倉庫 tee /etc/yum.repos.d/docker.repo <<-'EOF' [dockerrepo] name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF #安裝docker yum install docker #模糊查詢docker鏡像 docker images|grep 鏡像名
#啓動 systemctl start docker #或重啓 systemctl restart docker #關閉 systemctl stop docker #設置爲開機啓動項 systemctl enable docker
docker search <image> #或 docker pull 鏡像名
docker image ls #或 docker images
#查看容器 docker ps #或 docker container ls #查看全部容器,包括中止的容器 docker ps -a
docker run --name 自定義容器名 -d -p 端口號:端口號 鏡像名 #運行mysql docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7
docker exec -it 320c57e3f20d /bin/bash
docker build -t 自定義鏡像名 . #命令末尾的點很重要,由於它表示在當前位置使用已聲明的dockerfile
FROM java:8 #須要的環境名 COPY springboot_docker-0.0.1-SNAPSHOT.jar / #複製目錄下的jar包 EXPOSE 8080 CMD java -jar springboot_docker-0.0.1-SNAPSHOT.jar #啓動jar包
docker search mysql INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 8028 [OK] docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2704 [OK] docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 601 [OK] docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 183 [OK] docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 111 docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 94 [OK] docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60 [OK] docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 51 docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK] docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 43 docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 31 docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 26 [OK] docker.io docker.io/zabbix/zabbix-web-apache-mysql Zabbix frontend based on Apache web-server... 26 [OK] docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 25 [OK] docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 20 docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 20 [OK] docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 13 docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 12 docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 9 docker.io docker.io/dsteinkopf/backup-all-mysql backup all DBs in a mysql server 6 [OK] docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 docker.io docker.io/jelastic/mysql An image of the MySQL database server main... 1 docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK] docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... 0 [OK] docker.io docker.io/widdpim/mysql-client Dockerized MySQL Client (5.7) including Cu... 0 [OK]
docker pull mysql:5.6.43 Trying to pull repository docker.io/library/mysql ... 5.6.43: Pulling from docker.io/library/mysql 27833a3ba0a5: Pull complete 864c283b3c4b: Pull complete cea281b2278b: Pull complete 8f856c14f5af: Pull complete 9c4f38c23b6f: Pull complete 688342d0934f: Pull complete 1f90d0188066: Pull complete 6d31565f1a00: Pull complete 12062e921a90: Pull complete 066ae780ca9a: Pull complete f6eece737bcc: Pull complete Digest: sha256:de2913a0ec53d98ced6f6bd607f487b7ad8fe8d2a86e2128308ebf4be2f92667 Status: Downloaded newer image for docker.io/mysql:5.6.43
systemctl start docker
docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql 5.6.43 bc788a6a2745 2 weeks ago 256 MB
docker run --name db001 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:5.6.43 #或者 docker run -d --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -v /var/lib/mysql:/var/lib/mysql -d mysql:5.7.25 445e43800b559e2869a3cc92f17cf87482ed5a700588f04ec6b4eb4d58981e58
docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 445e43800b55 mysql:5.6.43 "docker-entrypoint..." 16 seconds ago Up 13 seconds 0.0.0.0:3306->3306/tcp db001