docker安裝使用

yemaiqingxiang發表於2019-03-09

安裝命令

wgc@wanggc:~$ curl -fsSL get.docker.com -o get-docker.sh
wgc@wanggc:~$ sh get-docker.sh --mirror Aliyun
$ sudo chmod +x /usr/local/bin/docker-compose
Centos上安裝docker
$ sudo yum install docker
複製程式碼
apt 簡單的安裝
1.sudo apt-get install -y curl

2.curl -sSL https://get.docker.com/ubuntu/ | sudo sh

3.curl的安裝
檢視curl是否安裝;

whereis curl

安裝curl:
sudo apt-get install -y curl

利用裝好的Docker執行一個容器

讓容器輸出hello Word

sudo docker run ubuntu echo "Hellow word"
複製程式碼

開啟

$ systemctl start docker

成功提示

+ sudo -E sh -c docker version
複製程式碼

檢視安裝版本

wgc@wanggc:~$ docker version
複製程式碼

加速器 /etc/docker/daemon.json

{
 "registry-mirrors": [
   "https://registry.docker-cn.com"
 ]
}
複製程式碼

Docker 常規操作

$ docker ps [OPTIONS] 列出容器
$ docker logs [OPTIONS] CONTAINER 獲取容器的日誌
$ docker rm [OPTIONS] CONTAINER [CONTAINER...] 刪除一個或多少容器
複製程式碼

Docker-compose 安裝

安裝 & 解除安裝

# 下載映象
$ sudo curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# 驗證是否成功安裝
$ docker-compose version
複製程式碼

Docker-compose 操作

$ docker ps -a  檢視執行容器  
$ docker stop  \<ID> 關閉
$ docker-compose up 啟動
$ docker-compose down 停止
$ docker-compose up -d tomcatname 啟動容器

複製程式碼

gitlab /usr/local/docker/gitlab/docker-compose.yml

version: "3"
services:
 gitlab:
   image: twang2218/gitlab-ce-zh
   container_name: gitlab
   restart: always
   hostname: '192.168..0.109'
   environment:
     GITLAB_OMNIBUS_CONFIG: |
       external_url "http://192.168.0.109:9090"
       gitlab_rails['gitlab_shell_ssh_port'] = 2222
       gitlab_rails['gitlab_email_enabled'] = true
       gitlab_rails['gitlab_email_from'] = 'xxx@xxxxx.com'
       gitlab_rails['gitlab_email_display_name'] = 'xxx'
       gitlab_rails['gitlab_email_reply_to'] = 'xxxx@xxxxx.com'
       gitlab_rails['smtp_enable'] = true
       gitlab_rails['smtp_address'] = "smtp.mxhichina.com"
       gitlab_rails['smtp_port'] = 465
       gitlab_rails['smtp_user_name'] = "xxx@xxxx.com"
       gitlab_rails['smtp_password'] = "xxxxx"
       gitlab_rails['smtp_domain'] = "smtp.mxhichina.com"
       gitlab_rails['smtp_authentication'] = "login"
       gitlab_rails['smtp_enable_starttls_auto'] = true
       gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
       gitlab_rails['smtp_tls'] = true
   ports:
     - '9090:9090'
     - '2222:22'
   volumes:
    -  '/usr/local/docker/gitlab/config:/etc/gitlab'
    -  '/usr/local/docker/gitlab/data:/var/opt/gitlab'
    -  '/usr/local/docker/gitlab/logs:/var/log/gitlab'
   logging:
     driver: "json-file"
     options:
       max-size: "20m"
       max-file: "10"
複製程式碼

mysql /usr/local/docker/mysql/docker-compose.yml

  mysqlname:
    restart: always
    image: mysql:5.7.22
    container_name: mysqlname
    ports:
      - 3306:3306
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: 123456
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
    volumes:
      - mysql-data:/var/lib/mysql
複製程式碼

tomcat /usr/local/docker/tomcat/docker-compose.yml

  tomcatname:
    restart: always
    image: tomcat
    container_name: tomcatname
    ports:
      - 8080:8080
    volumes:
      - /usr/local/docker/web/:/usr/local/tomcat/webapps
    environment:
      TZ: Asia/Shanghai
複製程式碼

Linux 常用命令

tar -zxvf # 解壓
pwd # 檢視全路徑

複製程式碼

java 安裝 /usr/local/java/jdk1.8.0_201

maven 安裝 /usr/local/maven/apache-maven-3.6.0


$ vi /etc/profile # 修改使用者變數

export MAVEN_HOME=/usr/local/maven/apache-maven-3.6.0
JAVA_HOME=/usr/local/java/jdk1.8.0_201
PATH=$JAVA_HOME/bini:$MAVEN_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH

$ source /etc/profile  #配置生效
複製程式碼

maven 使用

$ mvn clean package -Dmaven.test.skip=true # 下載包

複製程式碼

檢視tomcat日誌 apache - tomcat-8.5.23/logs# tail - f catalina.out

給超級管理員設定密碼

sudo passwd root
切換root
wgc@wanggc:/$ su
Password: 
root@wanggc:/# 
設定允許遠端登入root
sudo /etc/ssh/sshd_config
vi /etc/ssh/sshd_config
複製程式碼

檢視容器

docker ps

檢視日誌

docker logs -f #{ID}

相關文章