Ubuntu使用Docker

参考:
Docker Hub
Docker Nginx – dotcloudid/nginx(Remove “Server: nginx” and server_tokens, Add crontab and timezone)
Docker Practice
MySQL OFFICIAL REPOSITORY

安装方式 – Shell:
https://get.docker.com/

# This script is meant for quick & easy install via:
$ curl -fsSL get.docker.com -o get-docker.sh
$ sh get-docker.sh

常用命令

帮助:docker [command] –help

查看镜像:docker images [-a]
查看容器:docker ps [-a]
拉取镜像:docker pull

Dockerfile创建镜像:docker build -t [dotcloudid/nginx] .
镜像发布:docker login + docker push

执行:docker run -p 80:80 –name=nginx -d [dotcloudid/nginx]
编辑:docker exec -it nginx sh(进入容器命令窗口)

清空容器/镜像/卷

删除容器:docker rm [-f]
删除镜像:docker rmi [-f]
删除卷:docker volume rm [-f]

# Delete all containers
$ docker rm $(docker ps -a -q)
# Delete all images
$ docker rmi $(docker images -q)
# Delete all volumes
$ docker volume rm $(docker volume ls -q)

查看状态,清理

$ docker system df
$ docker system prune [-a]

示例 – MySQL

docker pull mysql:5.7
# docker images查看
docker run --name=mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=${PASSWORD} -d mysql:5.7
# docker ps检查
docker exec -it mysql sh

# 开启远程授权
# grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option;
# flush privileges;
> mysql -uroot -p${PASSWORD}
> grant all privileges on *.* to 'root'@'%' identified by '${PASSWORD}' with grant option;
> flush privileges;
> exit;

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注