Workdir
Format Workdir/path/to/workdir
Specify working directory for subsequent run, CMD, or entrypoint two dockerfile create a mirror –dockerfile build Nginx instance1 Edit Dockerfile file
Vim Dockerfile#set the base image to Centosfrom centos# File author/maintainermaintainer lv# Install Necessar Y toolsrun yum install-y pcre-devel wget net-tools gcc zlib zlib-devel make openssl-devel# install Nginxadd Http://nginx. Org/download/nginx-1.8.0.tar.gz. RUN tar zxvf nginx-1.8.0.tar.gzrun mkdir-p/usr/local/nginxrun cd nginx-1.8.0 &&/configure--prefix=/usr/local /nginx && make && make Installrun rm-fv/usr/local/nginx/conf/nginx.confcopy. nginx_conf/usr/local/ NGINX/CONF/NGINX.CONF//Prepare a configuration file in the current directory. # Expose Portsexpose 80# Set The default command to execute when creating a new containerentrypoint/usr/local/nginx/sbin/ Nginx && tail-f/etc/passwd
Note: Here tail-f/etc/passwd function is to allow the container to continue to operate. If not added, the container will exit just after it is started.
2 Creating the Image:
docker build -t centos_nginx
Create a mirror.
docker images
You can see our new image.
docker run -itd -p 81:80 centos_nginx bash
Start container
3 Simple test
If the nginx in the container, the configuration file, the default virtual host is correct, we will be able to access the Web directly on the host
curl 127.0.0.1:81
The default page is accessed.
Three-use Docker compose Deployment ServicesDocker compose allows us to quickly and efficiently manage the start, stop, restart, and other operations of the container, similar to the shell script under Linux, based on YAML syntax, in which we can describe the architecture of the application, such as what image, data volume, network mode, listening port and other information. We can define a multi-container application (such as Jumpserver) in a compose file, and then start the application with that compose.
Install the Compose method as follows
curl -L https://github.com/docker/compose/releases/download/1.17.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-composechmod 755 !$
docker-compose version
View version Information
Compose distinguishes between version 1 and version 2 (Compose 1.6.0+,docker Engine 1.10.0+). Version 2 supports more directives. Version 1 does not declare that the versions default to "Version 1". Version 1 will be deprecated in the future.
Vim DOCKER-COMPOSE.YML//
version: "2" //定义使用的命令版本services:app1: // 定义第一个应用。名字没有实际含义image: centos_nginx // 定义要使用的镜像ports: - "8080:80" // 定义容器和宿主机的端口映射关系networks: - "net1" //定义容器使用的网络volumes: - /data/:/data // 定义数据卷容器共享目录及和宿主机目录映射关系,相当于-v选项app2:image: centosnetworks: - "net2"volumes: - /data/:/data1entrypoint: tail -f /etc/passwd //启动容器时附加执行一条命令networks:net1:driver: bridge //定义容器使用的网络模型为桥接net2:driver: bridge
Note: The Tail-f/etc/passwd here works the same as the Centos_nginx created above. It is also intended to keep the container running. App1 inside the mirror Centos_nginx already have this sentence, no longer repeat. There are no similar statements in the CentOS image in App2, so it needs to be added to the entrypoint.
docker-compose up -d
can start two containers//up equivalent to create again start,-D drop into the background.
Docker-compose--help//View available options
Docker-compose PS/DOWN/STOP/START/RM
Reference document on the Docker-compose syntax http://www.web3.xin/index/article/182.html