Docker 容器是一個開源的應用容器引擎,讓開發者可以以統一的方式打包他們的應用以及依賴包到一個可移植的容器中,然后發布到任何安裝了docker引擎的服務器上(包括流行的Linux機器、windows機器),也可以實現虛擬化。容器是完全使用沙箱機制,相互之間不會有任何接口(類似 iPhone 的 app)。幾乎沒有性能開銷,可以很容易地在機器和數據中心中運行。最重要的是,他們不依賴于任何語言、框架包括系統。
[root@host1 ~]# vim docker-compose.yml
version: '3'
services:
web:
image: nginx:latest
ports:
- "5000:5000"
links:
- redis
redis:
image: redis[root@host1 ~]# docker-compose up -d[root@host1 ~]# docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------
root_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp
root_web_1 nginx -g daemon off; Up 0.0.0.0:5000->5000/tcp, 80/tcp[root@host1 ~]# docker-compose logs[root@host1 ~]# docker-compose down
Stopping root_web_1 ... done
Stopping root_redis_1 ... done
Removing root_web_1 ... done
Removing root_redis_1 ... done
Removing network root_default[root@host1 ~]# vim Dockerfile
#Nginx
#Version 1.0.1
#Author zxhk
#Base image
FROM centos:7
#Maintainer
MAINTAINER zxhk08@qq.com
#Commands
RUN rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y nginx
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx"][root@host1 ~]# docker build -t newweb/nginx:v1-1 ./[root@host1 ~]# vim docker-compose.yml
version: '2'
services:
web1:
image: newweb/nginx:v1.0.1
volumes:
- /data/www1:/usr/share/nginx/html
ports:
- "8080:80"
web2:
image: newweb/nginx:v1.0.1
volumes:
- /data/www2:/usr/share/nginx/html
ports:
- "8081:80"
web3:
image: newweb/nginx:v1.0.1
volumes:
- /data/www3:/usr/share/nginx/html
ports:
- "8082:80"[root@host1 ~]# docker-compose up -d[root@host1 ~]# docker-compose ps[root@host1 ~]# docker-compose logs[root@host1 ~]# docker-compose down 免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。