Docker-Compose安裝部署及常用命令整理


 

Docker-Compose是一個部署多個容器的簡單但是非常必要的工具.安裝Docker-Compose之前,請先安裝 python-pip

一、安裝 python-pip
[root@workbench-test ~]# pip -V
-bash: pip: command not found
  
[root@workbench-test ~]# yum install python-pip
[root@workbench-test ~]# yum -y install epel-release
[root@workbench-test ~]# yum install python-pip
[root@workbench-test ~]# pip install --upgrade pip
  
[root@workbench-test ~]# pip -V
pip 10.0.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
  
二、安裝Docker Compose
[root@workbench-test ~]# pip install docker-compose
---------------------------------------------------------------------------------------
如果報錯:
ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out
解決:
# pip --default-timeout=200 install -U docker-compose
--------------------------------------------------------------------------------------
如果執行中報錯:
Setup script exited with error: command 'gcc' failed with exit status 1異常
  
這是沒有正確安裝Python開發環境導致,解決如下:
# yum install python-devel
# yum install libevent-devel
# pip install gevent
# yum install groupinstall 'development tools'
--------------------------------------------------------------------------------------
  
檢驗docker-compose是否安裝成功
[root@workbench-test ~]# docker-compose --version
docker-compose version 1.21.2, build a133471
--------------------------------------------------------------------------------------
如果報錯:
pkg_resources.DistributionNotFound: backports.ssl-match-hostname>=3.5
解決方法:更新backports.ssl-match-hostname的版本,在終端輸入命令
# pip install --upgrade backports.ssl_match_hostname

                                                                                                                                                                   
Docker-compose常用命令

# docker-compose --help 命令可以查看到命令列表
build               Build or rebuild services
bundle              Generate a Docker bundle from the Compose file
config              Validate and view the Compose file
create              Create services
down                Stop and remove containers, networks, images, and volumes
events              Receive real time events from containers
exec                Execute a command in a running container
help                Get help on a command
images              List images
kill                Kill containers
logs                View output from containers
pause               Pause services
port                Print the public port for a port binding
ps                  List containers
pull                Pull service images
push                Push service images
restart             Restart services
rm                  Remove stopped containers
run                 Run a one-off command
scale               Set number of containers for a service
start               Start services
stop                Stop services
top                 Display the running processes
unpause             Unpause services
up                  Create and start containers
version             Show the Docker-Compose version information

==================================================================================
docker-compose up -d nginx                           構建建啟動nignx容器
docker-compose exec nginx bash                       登錄到nginx容器中
docker-compose down                                  刪除所有nginx容器,鏡像
docker-compose ps                                    顯示所有容器
docker-compose restart nginx                         重新啟動nginx容器
docker-compose run --no-deps --rm php-fpm php -v     在php-fpm中不啟動關聯容器,並容器執行php -v 執行完成后刪除容器
docker-compose build nginx                           構建鏡像        
docker-compose build --no-cache nginx                不帶緩存的構建。
docker-compose logs  nginx                           查看nginx的日志 
docker-compose logs -f nginx                         查看nginx的實時日志

 
==================================================================================
docker-compose config  -q                            驗證(docker-compose.yml)文件配置,當配置正確時,不輸出任何內容,當文件配置錯誤,輸出錯誤信息。 
docker-compose events --json nginx                   以json的形式輸出nginx的docker日志
docker-compose pause nginx                           暫停nignx容器
docker-compose unpause nginx                         恢復ningx容器
docker-compose rm nginx                              刪除容器(刪除前必須關閉容器)
docker-compose stop nginx                            停止nignx容器
docker-compose start nginx                           啟動nignx容器

免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號  © 2018-2020 CODEPRJ.COM