Centos7環(huán)境下安裝docker,亦可ubantu\windos\mac只是dicker安裝的命令不同可自行安裝如绸,這里不做介紹
——第一步安裝docker 有則忽略
# 1旭贬、yum 包更新到最新
yum update
# 2稀轨、安裝需要的軟件包奋刽, yum-util 提供yum-config-manager功能杨名,另外兩個(gè)是devicemapper驅(qū)動依賴的
yum install -y yum-utils device-mapper-persistent-data lvm2
# 3趁蕊、 設(shè)置yum源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 4任柜、 安裝docker逆皮,出現(xiàn)輸入的界面都按 y
yum install -y docker-ce
# 5潜索、 查看docker版本誊抛,驗(yàn)證是否驗(yàn)證成功
docker -v
——第二步將vue項(xiàng)目放入服務(wù)器任意位置
1列牺,在本地創(chuàng)建docker-vue文件夾,將打包好的dist文件夾放入gocker-vue
2拗窃,在docker-vue文件夾中新建文本文檔為dockerfile.txt瞎领,并在文檔中寫入如下內(nèi)容
FROM nginx:latest
MAINTAINER xxh
COPY dist/ /usr/share/nginx/html/
在docker-vue文件夾中新建nginx.conf 并寫入以下內(nèi)容
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
client_max_body_size 20m;
server {
listen 80;
server_name xxh;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
3,將docker-vue上傳至服務(wù)器任意目錄随夸,將dockerfile.txt重命名為dockerfile.
4.通過Xshell等工具進(jìn)入到服務(wù)器docker-vue文件夾下
[root@iz2zeeln8k6ea70n7a49erz docker-vue]#
輸入如下命令
docker build -t gentle-vue .
5.啟動容器
docker run -p 80:80 -d --name gentle-vue gentle-vue
6.瀏覽器訪問服務(wù)器地址即可
刪除容器
先列出有哪些容器(列出所有的):docker ps -a
顯示所有容器:docker ps -a
只顯示容器ID:docker ps -q
要先暫停容器九默,才能刪除:
暫停所有容器:docker stop (docker ps -aq)
刪除單個(gè)容器:docker rm < CONTAINER ID >
強(qiáng)制刪除 -f, --force:docker rm -f < CONTAINER ID >
刪除指定鏈接-l, --link:docker rm -l < CONTAINER ID >
刪除容器關(guān)聯(lián)數(shù)據(jù)卷-v --volumes:docker rm -v < CONTAINER ID >
刪除鏡像
列出鏡像:docker images
刪除鏡像:
刪除單個(gè)鏡像:docker rmi < IMAGE ID >
刪除所有鏡像:docker rmi (docker images -q)
注:不明白的命令使用 --help查詢