docker commonly used commands:
docker pull acquiring Image
Docker Build Creating Image
Docker listed ImagesRF Royalty Free Image
Docker RUN run container
Docker STOP to stop container
Docker rmi Delete Image
Docker PS listed container
Docker PS -a list the history of the container
docker rm [ "idlist"] delete contain more than a history
docker run -p 8080: 80 -d daocolud.io/nginx run nginx
Docker cp index.html [ "the above mentioned id"]: // usr / report this content share / nginx / HTML temporarily modify nginx Home
docker commit -m 'fun' [ "id"] [ 'name '] save the modified image
Creating a simple docker mirror Dockerfile
1. Create a file Dockerfiler
2. Edit the file, vim Dockerfile
Input:
FROM alpine:latest
MAINTAINER yrg
CMD echo "Hello Docker"
3. Create a mirror
docker build -t hello_docker .
-t: 'to mirror a hello_docker label . ' is a path name, underneath all the contents are given to let him have a docker engine image
4. View image
5. Run image
Dockerfile combat (to create a more sophisticated image)
1. Create a folder, create a file Dockerfile
2. Edit the file, add the following:
FROM ubuntu # name
MAINTAINER yrg # of
RUN sed -i 's / archive.ubuntu.com / mirrors.ustc.edu.cn / g' /etc/apt/sources.list # accelerated mirroring
RUN apt-get update # update Ubuntu library
RUN apt-get install -y nginx # installed nginx commands
cOPY index.html / var / www / html # ready to copy index.html container (different Ubuntu is not the same)
EntryPoint [ "/ usr / sbin / nginx "," - g " ," daemon off; "] # containers point, will be performed as a foreground nginx
EXPOSE 80 # port
3. Create a mirror
docker build -t yrg/hello-nginx .
4. Run Mirror
docker run -p 80:80 -d yrg/hello-nginx
5.curl http: // localhost to view it
Dockerfile grammar
Mirror stratified
volume
Introduction: providing independent persistent storage vessel
操作:1.docker run -d --name nginx -v /usr/share/nginx/html nginx
2.docker inspect nginx 查看详情
3.查看文件
ls /var/lib/docker/volumes/76db0f001f7675c41f511400dd09be16fe2e785f114c7f1a1e0f860c3b36f4fd/_data
4.可以修改index文件进入容器中下查看
docker exec -it /bin/bash
cd /usr/share/nginx/html
cat index.html
方式二挂载:
docker run -p 80:80 -d -v $PWD/html:/usr/share/nginx/html nginx
三:
docker create -v $PWD/data:/var/mydata --name data_container ubuntu
进入Ubuntu
docker run -it --volumes-from data_container ubuntu /bin/bash
输入mount
进入/var/mydata,输入ls,可以看到为空
创建一个文本,whatever.txt,然后退出
进入data,输入ls,可以看的当前目录下也创建了一个whatever.txt的文本
说明挂载成功
Registry(镜像仓库)
# docker search whalesay :从仓库中搜索镜像
# docker pull whalesay :从仓库中下载镜像
# docker push myname/whalesay :将自己做的镜像上传到仓库
国内的一些仓库:
daocloud
时速云
aliyun
实战:
docker search whalesay
下载镜像
docker pull docker/whalesay
查看镜像:
运行镜像
docker run docker/whalesay cowsay dockerisfun
docker tag docker/whalesay godyrg/whalesay :产生一个新的tag的镜像
上传镜像:
进行登录
docker login
登录成功后 ,上传镜像
docker push godyrg/whalesay
进入 https://hub.docker.com/ ,可以看到上传的镜像
docker-compose(多容器)
Mac/windows :自带
linux:需要安装:
curl -L "https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose :给文件夹赋予权限
输入
docker-compose --version
如果显示版本号,安装成功
实战:
创建 ghost,nginx,data文件夹
在ghost文件夹中创建Dockerfile
编辑Dockerfile文件
FROM ghost
COPY ./config.js /var/lib/ghost/config.js
EXPOSE 2368
CMD ["npm","start","--production"]
接着
var path = require('path'),
config;
config={
prodution: {
url: 'http://mytestblog.com',
mail: {},
database: {
client: 'mysql,
connection: {
host : 'db',
user : 'ghost',
password : 'ghost',
database : 'ghost',
charset : 'utf8'
},
debug:false
},
path:{
contentPath:path.join(process.env.GHOST_CONTENT,'/')
},
server: {
host: '0.0.0.0',
port: '2368'
}
}
} ;
moudle.exports = config;
保存退出
进入刚刚创建的nginx目录
创建Dockerfile文件,编辑
FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
保存退出
创建nginx.conf配置文件
worker processes 4;
events {worker_connections 1024}
http {
server{
listen 80;
loction / {
proxy_pass http://ghost-app:2368;
}
}
}
最后准备docker-compose.yaml文件
version: '2'
networks:
ghost:
services:
ghost-app:
build: ghost
networks:
- ghost
depends_on:
- db
ports:
- "2368:2368"
nginx:
build: nginx
networks:
- ghost
depends_on:
- ghost-app
ports:
- "80:80"
db:
image: "mysql :5.7.15"
networks:
- ghost
enviroment:
MYSQL_ROOT_PASSWORD: mysqlroot
MYSQL_USER: ghost
MSYQL_PASSWORD: ghost
volumes:
- $PWD/data:/var/lib/mysql
ports:
- "3306:3306"
docker-compose up -d 进行挂起(无镜像,系统帮忙做一个镜像)
docker-compose stop 停止(出现错误的不停止)
docker-compose rm 停止(错误的也停止)
docker-compose build (自己构建一个镜像)