공식가이드 : https://docs.gitlab.com/omnibus/docker/

Installation from source GitLab 을 설치 하다가 문제가 생겨 Docker 로 옮겨와서 테스트를 하고 있습니다.

GitLab Requirments : https://docs.gitlab.com/ce/install/requirements.html OS 의 경우 대부분의 OS 를 지원 합니다.

일전에 포스트한 FreeBSD(Unsupported Unix distributions 라고 문서에 나와 있지만 설치가 됩니다.)

에서도 동작하며 일반적으로 많이 사용하는 Linux 에서는 설치하는데 문제가 없습니다.

(Ubuntu / Debian / CentOS / openSUSE 등) Storage 의 경우 GitLab 을 사용하는 용량만큼 달라질수 있으며 사용량이 많을 경우 LVM 등으로 붙여서 사용하는것이 용의해 보입니다.

또한 SSD 를 사용하여 응답속도를 조금더 빠르게 할수 있습니다.

cpu 의 경우 2 core 의 경우 500 명의 사용자를 지원 하고 1 core 의 경우 100명의 사용자를 지원 하지만 응용프로그램이 약깐 느려질수 있습니다. Memory 의 경우 4G + 4G Swap 최대 100명 사용자를 지원 하지만 속도가 느리고 8G 사용을 권장 합니다. 테스트 머신의 경우 ubuntu 16.04 / 2core cpu / 4G memory 사용 하여 테스트를 진행 하였습니다.

 

 

가이드 부분에 보면 아주 쉽게 설명이 되어 있습니다.

아래 내용과 동일하게 테스트를 해도 되지만 관리상 편하게 몇군대를 수정 하였습니다.

GitLab 제공 Docker-compose.yml 파일

web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.example.com'
      # Add any other gitlab.rb configuration here, each on its own line
  ports:
    - '80:80'
    - '443:443'
    - '22:22'
  volumes:
    - '/srv/gitlab/config:/etc/gitlab'
    - '/srv/gitlab/logs:/var/log/gitlab'
    - '/srv/gitlab/data:/var/opt/gitlab'

 

ports 부분의 경우 22:22 으로 연결을 해줍니다.

기본적으로 ssh 연결포트로 사용하기 때문에 해당 포트를 알려지지 않은 포트로 변경 합니다.

volume 부분의 경우 최상위 디렉토리가 아닌 Docker 관리 디렉토리에서 변경을 한다면 GitLab 서비스와 관리 하기 편하기 때문에

Workspcae/gitlab 아래의 디렉토리로 설정을 합니다.

 

docker-compose 설치

test@docker-test:~/Workspace$ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
test@docker-test:~/Workspace$ sudo chmod +x /usr/local/bin/docker-compose
test@docker-test:~/Workspace$ docker-compose --version

 

docker-compose.yml 파일 생성

gitlab 디렉토리를 생성후 docker-compose.yml 파일을 생성합니다.

test@docker-test:~/Workspace/gitlab$ vi docker-compose.yml
web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'https://gitlab.example.com'
  ports:
    - '80:80'
    - '443:443'
    - '1234:22'
  volumes:
    - './srv/gitlab/config:/etc/gitlab'
    - './srv/gitlab/logs:/var/log/gitlab'
    - './srv/gitlab/data:/var/opt/gitlab'

test@docker-test:~/Workspace/gitlab$

 

docker-compose 실행

test@docker-test:~/Workspace/gitlab$ docker-compose up -d --build

 

external_url ‘https://gitlab.example.com’  의 경우 https 로 할경우 Web에서 접속을 https 로 접속을 해야 합니다.

http 로는 접속을 할수 없습니다.

http 를 사용하기 위해선 external_url ‘http://gitlab.example.com’ 로 설정 하시면 됩니다.

 

http 확인

Windows hosts 추가후 test domain 을 사용하였습니다.

 

https 확인

GitLab Server ip 로 접속시에도 동일합니다. 

 

 

http 접속 확인

docker-compose 의

external_url ‘https://gitlab.example.com’ => external_url ‘http://gitlab.example.com’ 부분을 변경하였습니다.

실제로 사용할 경우 디렉토리를 삭제후 다시 만들어 사용하는걸 권장합니다.

root user 의 password 를 설정 합니다.

 

docker-compose up -d –build 후 약 1분 ~ 2분 정도의 시간이 필요 합니다.

GitLab Service 가 정상적으로 올라가지 않은상태에서 웹사이트 접속시 아래와 같은 화면을 확인할수 있습니다.

 

 

root User 로 로그인

 

 

 

 

Docker-compose mkdocs + nginx

별도의 mkdocs container 가 아닌 기본 Nginx 로 mkdocs Test 를 진행 했습니다.

추후 용도에 맞게 php + mysql 등을 설치 하여 사용하기 위하여 docker-compose 를 사용하였습니다.

mkdocs 설치의 경우 포스트를 참고해주세요.

Ubuntu mkdocs 설치

 

Docker-compose 설치

test@docker-test:~/Workspace$ sudo curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
test@docker-test:~/Workspace$ sudo chmod +x /usr/local/bin/docker-compose
test@docker-test:~/Workspace$ docker-compose --version

 

디렉토리 구조 

test@docker-test:~/Workspace/mkdocs$ tree
.
├── docker-compose.yml
├── nginx
│   └── conf
│   └── default.conf
└── wiki

3 directories, 2 files
test@docker-test:~/Workspace/mkdocs$

 

docker-compose.yml 파일 

test@docker-test:~/Workspace/mkdocs$ cat docker-compose.yml
version: '2'

services:
    nginx:
        image: nginx:1.10.2
        ports:
            - 80:80
        restart: always
        volumes:
            - ./nginx/conf:/etc/nginx/conf.d
            - ./wiki/wiki/site:/code

test@docker-test:~/Workspace/mkdocs$

 

nginx/conf/default.conf 파일

test@docker-test:~/Workspace/mkdocs$ cat nginx/conf/default.conf
server {
    listen       80 default_server;
    server_name  localhost _;
    index        index.html index.htm;
    root         /code;

    location / {
        autoindex on;
    }
}

test@docker-test:~/Workspace/mkdocs$

 

mkdocs project 생성

test@docker-test:~/Workspace/mkdocs/wiki$ mkdocs new wiki
INFO - Creating project directory: wiki
INFO - Writing config file: wiki/mkdocs.yml
INFO - Writing initial docs: wiki/docs/index.md
test@docker-test:~/Workspace/mkdocs/wiki$ cd wiki/
test@docker-test:~/Workspace/mkdocs/wiki/wiki$ mkdocs build
INFO - Building documentation to directory: /home/test/Workspace/mkdocs/wiki/wiki/site
test@docker-test:~/Workspace/mkdocs/wiki/wiki$

test@docker-test:~/Workspace/mkdocs$ docker-compose up -d --build
Creating network "mkdocs_default" with the default driver
Creating mkdocs_nginx_1 ... done
test@docker-test:~/Workspace/mkdocs$

 

docker-compose WiKi.js

참고페이지: https://docs.requarks.io/wiki/install/docker#using-docker-compose

 

wiki 디렉토리 생성 및 docker-compose.yml 파일생성

test@docker-test:~/Workspace$ mkdir wiki 
test@docker-test:~/Workspace/wiki$ vi docker-compose.yml
version: "3"
services:

  db:
    image: postgres:11-alpine
    environment:
      POSTGRES_DB: wiki
      POSTGRES_PASSWORD: wikijsrocks
      POSTGRES_USER: wikijs
    logging:
      driver: "none"
    restart: unless-stopped
    volumes:
      - db-data:/var/lib/postgresql/data

  wiki:
    image: requarks/wiki:2
    depends_on:
      - db
    environment:
      DB_TYPE: postgres
      DB_HOST: db
      DB_PORT: 5432
      DB_USER: wikijs
      DB_PASS: wikijsrocks
      DB_NAME: wiki
    restart: unless-stopped
    ports:
      - "80:3000"

volumes:
  db-data:

 

wikijs config.yml 파일 생성

sample 파일 : https://docs.requarks.io/install/docker

수정할 부분은 아래 내용참고

test@docker-test:~/Workspace/wiki$ vi config.yml

host: http://192.168.0.100

port: 3000

test@docker-test:~/Workspace/wiki$ docker-compose up -d --build
test@docker-test:~/Workspace/wiki$ docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                            NAMES
2178f46ab155        requarks/wiki:2      "docker-entrypoint.s…"   56 minutes ago      Up 56 minutes       3443/tcp, 0.0.0.0:80->3000/tcp   wiki_wiki_1
56a292756816        postgres:11-alpine   "docker-entrypoint.s…"   56 minutes ago      Up 56 minutes       5432/tcp                         wiki_db_1

 

 

 

 

 

jwilder/nginx-proxy image 이용 Nginx-web 컨테이너 추가

 

[docker] docker-compose Nginx-proxy multi-wordpress site

docker-compose Nginx-proxy 를 이용하여 Multi-Wordpress 컨테이너를 구성 하였습니다.

이번에는 WordPress 가 아닌 Nginx web-site를 구성 합니다.

 

Github

test@docker-test:~$ git clone https://github.com/visualwork/Docker-test.git

/Docker-test/test06 에 있습니다. 🙂

 

 

docker ps 확인시 nginx-proxy 컨테이너가 80 port 연결을 받아 다른 컨테이너의 Virtualhost로 접속하게 하였습니다.

test@docker-test:~/web-service$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
5d75a1fe1bc0        wordpress:latest      "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        80/tcp               wp_blog2
c5a3310e88d8        mariadb               "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        3306/tcp             wp_blog_db2
9e7e6c795f52        wordpress:latest      "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        80/tcp               wp_blog
242f3c32f658        mariadb               "docker-entrypoint.s…"   8 minutes ago       Up 8 minutes        3306/tcp             wp_blog_db
fc8761f89097        jwilder/nginx-proxy   "/app/docker-entrypo…"   11 minutes ago      Up 11 minutes       0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service$

 

ex) blog1 docker-compose.yml file

  wordpress:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     volumes:
       - ./web-data:/var/www/html
     environment:
       VIRTUAL_HOST: blog1.test.com

VIRTUAL_HOST : blog1.test.com 으로 설정 되어 있습니다. environment: 의 VIRTUAL_HOST 부분을 참조 하여 nginx-proxy 에서 자동으로 등록하게 되어 있습니다.

 

nginx 를 사용할 디렉토리를 생성후 임시docker-compose.yml 을 만들어 줍니다.

컨테이너 구동만을 테스트 하기 위하여 임시로 만드는 docker-compose 파일입니다.

test@docker-test:~/web-service$ mkdir www
test@docker-test:~/web-service$ cd www
test@docker-test:~/web-service/www$ vi docker-compose.yml
version: '2'
services:
  nginx-www:
    image: nginx:latest
    restart: always
    environment:
      - VIRTUAL_HOST=www.test.com
    container_name: nginx-www

networks:
  default:
    external:
      name: nginx-proxy

 

nginx-www 컨테이너를 구동합니다

test@docker-test:~/web-service/www$ docker-compose up -d --build
Pulling nginx-www (nginx:latest)...
latest: Pulling from library/nginx
8176e34d5d92: Already exists
5b19c1bdd74b: Pull complete
4e9f6296fa34: Pull complete
Digest: sha256:4771d09578c7c6a65299e110b3ee1c0a2592f5ea2618d23e4ffe7a4cab1ce5de
Status: Downloaded newer image for nginx:latest
Creating nginx-www ... done
test@docker-test:~/web-service/www$

 

nginx-www 컨테이너 확인

test@docker-test:~/web-service/www$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
7fcc8b64bf87        nginx:latest          "nginx -g 'daemon of…"   43 seconds ago      Up 42 seconds       80/tcp               nginx-www
5d75a1fe1bc0        wordpress:latest      "docker-entrypoint.s…"   12 minutes ago      Up 12 minutes       80/tcp               wp_blog2
c5a3310e88d8        mariadb               "docker-entrypoint.s…"   12 minutes ago      Up 12 minutes       3306/tcp             wp_blog_db2
9e7e6c795f52        wordpress:latest      "docker-entrypoint.s…"   15 minutes ago      Up 15 minutes       80/tcp               wp_blog
242f3c32f658        mariadb               "docker-entrypoint.s…"   15 minutes ago      Up 15 minutes       3306/tcp             wp_blog_db
fc8761f89097        jwilder/nginx-proxy   "/app/docker-entrypo…"   18 minutes ago      Up 18 minutes       0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/www$

 

nginx-proxy 컨테이너에 접속 합니다.

www.test.com ip 정보를 확인 합니다.

test@docker-test:~/web-service/www$ docker exec -it fc8761f89097 /bin/bash
root@fc8761f89097:/app# cat /etc/nginx/conf.d/default.conf
~중략
# www.test.com
upstream www.test.com {
                                ## Can be connect with "nginx-proxy" network
                        # nginx-www
                        server 172.18.0.7:80;
}
server {
        server_name www.test.com;
        listen 80 ;
        access_log /var/log/nginx/access.log vhost;
        location / {
                proxy_pass http://www.test.com;
        }
}
root@fc8761f89097:/app# 

 

docker inspect 명령어를 이용하여 nginx-www 에 설정된 ip  정보를 확인 합니다.

test@docker-test:~/web-service/www$ docker inspect nginx-www |grep 172
                    "Gateway": "172.18.0.1",
                    "IPAddress": "172.18.0.7",
test@docker-test:~/web-service/www$

정상적으로 설정이 되어 있습니다. 🙂

docker-compose down 하여 컨테이너를 정지 합니다.

test@docker-test:~/web-service/www$ docker-compose down
Stopping nginx-www ... done
Removing nginx-www ... done
Network nginx-proxy is external, skipping
test@docker-test:~/web-service/www$

 

디렉토리 생성

test@docker-test:~/web-service/www$ mkdir www-data
test@docker-test:~/web-service/www$ mkdir -p mariadb/db-data
test@docker-test:~/web-service/www$ mkdir -p nginx/conf
test@docker-test:~/web-service/www$ mkdir -p php/conf

 

docker-compose file 생성

test@docker-test:~/web-service/www$ vi docker-compose.yml
version: '2'
services:
  mysql:
    image: mariadb:10.3.1
    volumes:
      - ./mariadb/db-data/:/var/lib/mysql
      - ./mariadb/my.cnf:/etc/mysql/mariadb.conf.d/custom.cnf
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USER: docker
      MYSQL_PASSWORD: docker
      MYSQL_DATABASE: docker
    container_name: mariadb-www

  nginx-www:
    image: nginx:latest
    restart: always
    volumes:
      - ./nginx/conf:/etc/nginx/conf.d
      - ./www-data:/www

    environment:
      - VIRTUAL_HOST=www.test.com
    container_name: nginx-www

  php:
    build: php
    expose:
      - 9000
    restart: always
    volumes:
      - ./php/conf/php.ini:/usr/local/etc/php/conf.d/custom.ini
      - ./www-data:/www
    container_name: php-www


networks:
  default:
    external:
      name: nginx-proxy

 

nginx/conf/default.conf 파일생성

test@docker-test:~/web-service/www$ cd nginx/conf/default.conf
server {
    listen       80 default_server;
    server_name  localhost _;
    index        index.php index.html index.htm;
    root         /www;

    location / {
        try_files   $uri $uri/ /index.php?$query_string;
        autoindex on;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

 

php/Dockerfile 파일생성

test@docker-test:~/web-service/www$ vi php/Dockerfile
FROM php:7.1-fpm

RUN apt-get update

# Some basic extensions
RUN docker-php-ext-install -j$(nproc) json mbstring opcache pdo pdo_mysql mysqli

# Curl
RUN apt-get install -y libcurl4-openssl-dev
RUN docker-php-ext-install -j$(nproc) curl

# GD
RUN apt-get install -y libpng-dev libjpeg-dev
RUN docker-php-ext-install -j$(nproc) gd

# Intl
RUN apt-get install -y libicu-dev
RUN docker-php-ext-install -j$(nproc) intl

 

php/conf/php.ini 파일생성

test@docker-test:~/web-service/www$ vi php/conf/php.ini
display_errors = On
display_startup_errors = On
default_charset = "UTF-8"
html_errors = On
date.timezone = Asia/Seoul

 

mariadb/my.cnf 파일생성

test@docker-test:~/web-service/www$ vi mariadb/my.cnf
# MariaDB database server configuration file.
#
# You can copy this file to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port            = 3306
socket          = /var/run/mysqld/mysqld.sock
default-character-set = utf8mb4


# Here is entries for some specific programs
# The following values assume you have at least 32M ram

# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
#user           = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc_messages_dir = /usr/share/mysql
lc_messages     = en_US
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address           = 127.0.0.1
#
# * Fine Tuning
#
max_connections         = 100
connect_timeout         = 5
wait_timeout            = 600
max_allowed_packet      = 16M
thread_cache_size       = 128
sort_buffer_size        = 4M
bulk_insert_buffer_size = 16M
tmp_table_size          = 32M
max_heap_table_size     = 32M
#
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover_options = BACKUP
key_buffer_size         = 128M
#open-files-limit       = 2000
table_open_cache        = 400
myisam_sort_buffer_size = 512M
concurrent_insert       = 2
read_buffer_size        = 2M
read_rnd_buffer_size    = 1M
#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit               = 128K
query_cache_size                = 64M
# for more write intensive setups, set to DEMAND or OFF
#query_cache_type               = DEMAND
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# we do want to know about network errors and such
#log_warnings           = 2
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log[={0|1}]
slow_query_log_file     = /var/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit    = 1000
#log_slow_verbosity     = query_plan

#log-queries-not-using-indexes
#log_slow_admin_statements
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
#server-id              = 1
#report_host            = master1
#auto_increment_increment = 2
#auto_increment_offset  = 1
#log_bin                        = /var/log/mysql/mariadb-bin
#log_bin_index          = /var/log/mysql/mariadb-bin.index
# not fab for performance, but safer
#sync_binlog            = 1
expire_logs_days        = 10
max_binlog_size         = 100M
# slaves
#relay_log              = /var/log/mysql/relay-bin
#relay_log_index        = /var/log/mysql/relay-bin.index
#relay_log_info_file    = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only
#
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
#sql_mode               = NO_ENGINE_SUBSTITUTION,TRADITIONAL
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
default_storage_engine  = InnoDB
# you can't just change log file size, requires special procedure
#innodb_log_file_size   = 50M
innodb_buffer_pool_size = 256M
innodb_log_buffer_size  = 8M
innodb_file_per_table   = 1
innodb_open_files       = 400
innodb_io_capacity      = 400
innodb_flush_method     = O_DIRECT
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem

character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci



#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

[mysqldump]
quick
quote-names
max_allowed_packet      = 16M

[mysql]
#no-auto-rehash # faster start of mysql but no tab completion

[isamchk]
key_buffer              = 16M

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/

 

docker-compose 실행

test@docker-test:~/web-service/www$ docker-compose up -d --build

 

컨테이너 확인

test@docker-test:~/web-service/www$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
130f3eb196e3        www_php               "docker-php-entrypoi…"   10 seconds ago      Up 9 seconds        9000/tcp                 php-www
563f8bbccd33        mariadb:10.3.1        "docker-entrypoint.s…"   10 seconds ago      Up 9 seconds        0.0.0.0:3306->3306/tcp   mariadb-www
677fc32c5a4b        nginx:latest          "nginx -g 'daemon of…"   10 seconds ago      Up 9 seconds        80/tcp                   nginx-www
5d75a1fe1bc0        wordpress:latest      "docker-entrypoint.s…"   About an hour ago   Up About an hour    80/tcp                   wp_blog2
c5a3310e88d8        mariadb               "docker-entrypoint.s…"   About an hour ago   Up About an hour    3306/tcp                 wp_blog_db2
9e7e6c795f52        wordpress:latest      "docker-entrypoint.s…"   About an hour ago   Up About an hour    80/tcp                   wp_blog
242f3c32f658        mariadb               "docker-entrypoint.s…"   About an hour ago   Up About an hour    3306/tcp                 wp_blog_db
fc8761f89097        jwilder/nginx-proxy   "/app/docker-entrypo…"   About an hour ago   Up About an hour    0.0.0.0:80->80/tcp       nginx-proxy
test@docker-test:~/web-service/www$

 

test.php 파일생성

test@docker-test:~/web-service/www$ vi www-data/test.php
<?php phpinfo(); ?>

 

web browser 확인

 

mariadb 테스트

테스트를 위하여 그누보드5 설치를 진행 했습니다.

주의 Host : localhost -> db컨테이너 이름으로 변경해 줘야 합니다.

(Docker 네트워크에 관해서는 차후 포스팅 하도록 하겠습니다.)

 

 

설치후 로그인

 

blog1.test.com / blog2.test.com / www.test.com

 

수고 하셨습니다. 🙂

 

Docker 를 사용하다 보면 실행중인 컨테이너 삭제 및

모든 컨테이너 삭제및 모든 이미지를 삭제할일이 종종 생기곤 합니다.

아래 방법을 통하여 모든 컨테이너 삭제및 모든 이미지를 한번에 삭제 할수 있습니다. 🙂

  • 실행중인 모든 컨테이너 삭제

test@ubuntu1604:~$ docker rm -f `docker ps -a -q`

  • 모든 이미지 일괄 삭제 

test@ubuntu1604:~$ docker rmi -f `docker images`

  • docker-compose 이미지 삭제 

test@ubuntu1604:~/web-server$ docker-compose down --rmi all

 

docker swarm mode 구성

description:

To use Docker in swarm mode, install Docker. See installation instructions for all operating systems and platforms.

Current versions of Docker include swarm mode for natively managing a cluster of Docker Engines called a swarm. Use the Docker CLI to create a swarm, deploy application services to a swarm, and manage swarm behavior.

If you are using a Docker version prior to 1.12.0, you can use standalone swarm, but we recommend updating.

official page: https://docs.docker.com/engine/swarm/

 

vm 준비

docker-manager 192.168.192.10

docker-worker01 192.168.192.20

docker-worker02 192.168.192.30

3대의 vm 에는 docker가 설치 되어 있습니다.

Docker-manager
test@docker-manager:~$ docker -v
Docker version 18.02.0-ce, build fc4de44
test@docker-manager:~$

Docker-worker01
test@docker-worker01:~$ docker -v
Docker version 18.02.0-ce, build fc4de44
test@docker-worker01:~$

Docker-worker02
test@docker-worker02:~$ docker -v
Docker version 18.02.0-ce, build fc4de44
test@docker-worker02:~$

 

1. Create Docker Swarm cluster

docker-manager 에서 작업

command : docker swarm init –advertise-addr $docker-manager ip

test@docker-manager:~$ docker swarm init --advertise-addr 192.168.192.10
Swarm initialized: current node (mzsiydsvbyhafre4cppmfupvb) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5ar8gen44ij5gi7hlkmbbhdji2e06nvod2u86e5db7zwip9707-8f5nxu48rh841xdcj0na1vp0s 192.168.192.10:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

test@docker-manager:~$

 

docker manager node 확인

test@docker-manager:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
mzsiydsvbyhafre4cppmfupvb *   docker-manager      Ready               Active              Leader
test@docker-manager:~$

test@docker-manager:~$ docker info
Containers: 1
~중략
Swarm: active
 NodeID: mzsiydsvbyhafre4cppmfupvb
 Is Manager: true
 ClusterID: rnqp34pegl5rj9fqd1ex30x0h
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
  Force Rotate: 0
 Autolock Managers: false
 Root Rotation In Progress: false
 Node Address: 192.168.192.10
 Manager Addresses:
  192.168.192.10:2377
~중략

join-token 생성

docker-manager host 에서 작업

test@docker-manager:~$ docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-5ar8gen44ij5gi7hlkmbbhdji2e06nvod2u86e5db7zwip9707-8f5nxu48rh841xdcj0na1vp0s 192.168.192.10:2377

test@docker-manager:~$

 

 

docker-worker swarm 등록

docker-manager에서 생성한 join-token을 이용하여 worker node 를 등록 합니다.

docker-worker01 host 에서 작업

test@docker-worker01:~$ docker swarm join  --token SWMTKN-1-5ar8gen44ij5gi7hlkmbbhdji2e06nvod2u86e5db7zwip9707-8f5nxu48rh841xdcj0na1vp0s 192.168.192.10:2377
This node joined a swarm as a worker.
test@docker-worker01:~$ docker info |grep -i swarm
WARNING: No swap limit support
Swarm: active

 

docker-worker02 host 에서 작업

test@docker-worker02:~$ docker swarm join  --token SWMTKN-1-5ar8gen44ij5gi7hlkmbbhdji2e06nvod2u86e5db7zwip9707-8f5nxu48rh841xdcj0na1vp0s 192.168.192.10:2377
This node joined a swarm as a worker.
test@docker-worker02:~$ docker info |grep -i swarm
WARNING: No swap limit support
Swarm: active
test@docker-worker02:~$

 

docker-manager node 확인

test@docker-manager:~$ docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
mzsiydsvbyhafre4cppmfupvb *   docker-manager      Ready               Active              Leader
jvitfs6bmgr699p3nltzok0fw     docker-worker01     Ready               Active
hwkew1ktumxynqhqexjx5gn8l     docker-worker02     Ready               Active
test@docker-manager:~$

 

nginx test

docker run 의 경우 아래와 같이 사용하지만 docker swarm 의 경우 docker service create 명령어를 사용합니다.

docker run 실행시는 아래와 같이 사용 합니다. docker swarm 에서는 docker service create 명령어를 사용합니다. 🙂

test@docker-test:~$ docker run --name web-service -d -p 80:80 -p 443:443 nginx

 

docker service create 명령어

test@docker-manager:~$ docker service create --name web-service -p 80:80 -p 443:443 nginx
pgdc990uyesjmw399ayuraie9
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged
test@docker-manager:~$

 

!!! docker service create 명령어 사용시 –publish 옵션을 사용해야 합니다. 

test@docker-master:~$ docker service create --name web-service --publish 80:80 nginx
md8pzk0owb4s8ida55voqzlrb
overall progress: 1 out of 1 tasks
1/1: running   [==================================================>]
verify: Service converged
test@docker-master:~$

 

 

service 확인

test@docker-manager:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
pgdc990uyesj        web-service         replicated          1/1                 nginx:latest        *:80->80/tcp, *:443->443/tcp
test@docker-manager:~$ docker service ps web-service
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
wd1vyqp9eg2x        web-service.1       nginx:latest        docker-manager      Running             Running 29 seconds ago
test@docker-manager:~$

 

 

docker service scale 명령어를 사용하여 service 개수를 늘려 줍니다.

service 갯수를 줄일때도 동일하게 scale을 사용 합니다.

test@docker-manager:~$ docker service scale web-service=3
web-service scaled to 3
overall progress: 3 out of 3 tasks
1/3: running   [==================================================>]
2/3: running   [==================================================>]
3/3: running   [==================================================>]
verify: Service converged
test@docker-manager:~$


test@docker-manager:~$ docker service ps web-service
ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
wd1vyqp9eg2x        web-service.1       nginx:latest        docker-manager      Running             Running 20 minutes ago
bezi55mn78lf        web-service.2       nginx:latest        docker-worker01     Running             Running 42 seconds ago
vwpxbid1ez53        web-service.3       nginx:latest        docker-worker02     Running             Running 42 seconds ago
test@docker-manager:~$

 

docker service rm 

swarm 에서 사용중인 컨테이너 삭제시는 docker servier rm $service_name 으로 삭제 할수 있습니다.

test@docker-manager:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
pgdc990uyesj        web-service         replicated          1/1                 nginx:latest        *:80->80/tcp, *:443->443/tcp
test@docker-manager:~$ docker service rm web-service
web-service
test@docker-manager:~$ docker service ls
ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
test@docker-manager:~$

 

 

nginx-proxy multi-wordpress site

 

Site:https://www.draw.io

Nginx-proxy 를 이용하여 여러대의 wordpress container 사용할수 있습니다.

Nginx-proxy container 는 jwilder/nginx-proxy image 를 이용합니다.

 

Github

test@docker-test:~$ git clone https://github.com/visualwork/Docker-test.git

/Docker-test/test05 에 있습니다. 🙂

 

Nginx-proxy docker-compose.yml 파일 생성

test@docker-test:~$ mkdir -p web-service/nginx-proxy
test@docker-test:~$ cd web-service/nginx-proxy/
test@docker-test:~/web-service/nginx-proxy$ vi docker-compose.yml
## notice ##  $ docker network create nginx-proxy
version: "3"

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    restart: always

networks:
  default:
    external:
      name: nginx-proxy

 

Docker network 생성

Nginx-proxy container 구동전 docker network create commnad 를 이용하여 docker network 를 생성해야 합니다.

test@docker-test:~/web-service/nginx-proxy$ docker network create nginx-proxy
a5955ea1067f169fd1849ecd4c959c83319183dcb39188ddffe125423f9e5322
test@docker-test:~/web-service/nginx-proxy$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e64ced1895e7        bridge              bridge              local
a2b1f4b8cfba        host                host                local
a5955ea1067f        nginx-proxy         bridge              local
bb45871e893c        none                null                local
test@docker-test:~/web-service/nginx-proxy$

 

 

WordPress container

blog1 docker-compose.yml 파일 생성

container 사용시 db가 저장될 디렉토리와 web 이 저장될 디렉토리를 생성 합니다.

test@docker-test:~/web-service$ mkdir blog1
test@docker-test:~/web-service$ cd blog1/
test@docker-test:~/web-service/blog1$ mkdir web-data
test@docker-test:~/web-service/blog1$ mkdir db-data
test@docker-test:~/web-service/blog1$ tree
.
├── db-data
└── web-data

 

docker-compose 파일 생성

도메인의 경우 test.com 을 Test dns-server 로 미리 준비해 놓았습니다.

test@docker-test:~/web-service/blog1$ vi docker-compose.yml
version: "3"

services:
  db:
     image: mariadb
     volumes:
       - ./db-data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: test1234
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: test1234
     container_name: wp_blog_db

  wordpress:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     volumes:
       - ./web-data:/var/www/html
     environment:
       VIRTUAL_HOST: blog1.test.com
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: test1234
     container_name: wp_blog

networks:
  default:
    external:
      name: nginx-proxy

VIRTUAL_HOST 부분에 도메인을 설정해 줍니다. ex) blog1.test.com

 

Nginx-proxy 와 blog Wordprss 컨테이너를 구동 합니다.

Nginx-proxy 컨테이너 실행

test@docker-test:~/web-service$ cd ..
test@docker-test:~$ cd web-service/nginx-proxy/
test@docker-test:~/web-service/nginx-proxy$ docker-compose up -d --build
Pulling nginx-proxy (jwilder/nginx-proxy:latest)...
latest: Pulling from jwilder/nginx-proxy
e7bb522d92ff: Pull complete
6edc05228666: Pull complete
cd866a17e81f: Pull complete
d9f2d6a1f8f6: Pull complete
e9c7e986c8c1: Pull complete
a51bcd518fd9: Pull complete
66df98413ed2: Pull complete
aff8c6473b42: Pull complete
1c91fd608be1: Pull complete
7319453a5fbe: Pull complete
Digest: sha256:41506b2095779e6e64f34e26ccba35cb3668ee56a735cd740ac8c183af583294
Status: Downloaded newer image for jwilder/nginx-proxy:latest
Creating nginx-proxy ... done
test@docker-test:~/web-service/nginx-proxy$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/nginx-proxy$

이제부터 시스템의 모든 80 Port 의 경우 Nginx-proxy 에서 받아 들이게 됩니다.

 

blog1 컨테이너 실행

test@docker-test:~$ cd web-service/blog1/
test@docker-test:~/web-service/blog1$ docker-compose up -d --build
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
8176e34d5d92: Pull complete
f6c81892adaa: Pull complete
c8125c73b868: Pull complete
5ef22f6299b6: Pull complete
8537460e9a8c: Pull complete
b837671b83f0: Pull complete
366ea9d8b411: Pull complete
c4dd539af472: Pull complete
445753fb3ee6: Pull complete
6811f6b5d500: Pull complete
2ca365cdc65d: Pull complete
c91023a57f04: Pull complete
dcf0735fda8a: Pull complete
6b23fdc3538b: Pull complete
2eed880b86fe: Pull complete
798b2e547e59: Pull complete
159be43511e4: Pull complete
b5605b08f665: Pull complete
20d8e9ec2764: Pull complete
Digest: sha256:670e4156377063df1a02f036354c52722de0348d46222ba30ef6a925c24cd46a
Status: Downloaded newer image for wordpress:latest
Pulling db (mariadb:latest)...
latest: Pulling from library/mariadb
4176fe04cefe: Pull complete
d1e86691d483: Pull complete
c3f621b14a80: Pull complete
7b3f1b17db07: Pull complete
add1151625d9: Pull complete
d40e879009a8: Pull complete
0f888e49f29b: Pull complete
bd51d7af1551: Pull complete
6cf37448a3b3: Pull complete
0519e00d29e5: Pull complete
8f83e3487101: Pull complete
Digest: sha256:d5f0bc88ba397233677ff75b7b1de693d5e84527ecf2b4f59adebf8d0bcac3c4
Status: Downloaded newer image for mariadb:latest
Creating wp_blog ... done
Creating wp_blog_db ...
test@docker-test:~/web-service/blog1$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                NAMES
e83e15350e05        wordpress:latest      "docker-entrypoint.s…"   4 seconds ago       Up 2 seconds        80/tcp               wp_blog
ce6d5afb2986        mariadb               "docker-entrypoint.s…"   4 seconds ago       Up 4 seconds        3306/tcp             wp_blog_db
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   3 minutes ago       Up 3 minutes        0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/blog1$

 

web browser  접속

http://blog1.test.com 으로 접속합니다.

blog1 컨테이너 구성이 끝났습니다. Wordprss 설정을 한후 blog2 컨테이너를 구성 합니다.

 

 

blog2 docker-compose.yml 파일 생성

test@docker-test:~$ cd web-service/
test@docker-test:~/web-service$ mkdir blog2
test@docker-test:~/web-service$ cd blog2
test@docker-test:~/web-service/blog2$ mkdir db-data
test@docker-test:~/web-service/blog2$ mkdir web-data
test@docker-test:~/web-service/blog2$ vi docker-compose.yml
version: "3"

services:
  db2:
     image: mariadb
     volumes:
       - ./db-data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: test1234
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: test1234
     container_name: wp_blog_db2

  wordpress2:
     image: wordpress:latest
     expose:
       - 80
     restart: always
     volumes:
       - ./web-data:/var/www/html
     environment:
       VIRTUAL_HOST: blog2.test.com
       WORDPRESS_DB_HOST: db2:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: test1234
     container_name: wp_blog2

networks:
  default:
    external:
      name: nginx-proxy

 

docker-compose.yml 파일 변경 사항

db -> db2

wp_blog_db ->  wp_blog_db2

wordpress -> wordpress2

VIRTUAL_HOST: blog2.test.com

WORDPRESS_DB_HOST: db2:3306

container_name: wp_blog2

 

blog2 컨테이너 실행

test@docker-test:~/web-service/blog2$ docker-compose up -d --build
Creating wp_blog2 ... done
Creating wp_blog2 ...
test@docker-test:~/web-service/blog2$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED              STATUS              PORTS                NAMES
468a1f13cee1        wordpress:latest      "docker-entrypoint.s…"   About a minute ago   Up About a minute   80/tcp               wp_blog2
39d91c742082        mariadb               "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp             wp_blog_db2
fa9442409280        mariadb               "docker-entrypoint.s…"   9 minutes ago        Up 9 minutes        3306/tcp             wp_blog_db
416704fdb038        wordpress:latest      "docker-entrypoint.s…"   9 minutes ago        Up 9 minutes        80/tcp               wp_blog
2b9135ebe937        jwilder/nginx-proxy   "/app/docker-entrypo…"   21 minutes ago       Up 21 minutes       0.0.0.0:80->80/tcp   nginx-proxy
test@docker-test:~/web-service/blog2$

 

 

web browser  접속

http://blog2.test.com 으로 접속합니다.

 

 

 

Docker Command 정리 #01

문서버전: 2018.02.20 v0.1

docker help 명령어 확인시 아래와 같은 명령어를 확인 할수 있습니다.

자주 사용하는 명령어 위주로 정리 하였습니다.

일부 내용의 오타가 있을수 있습니다. 🙂

옵션 부분의 경우 차후 정리할 예정입니다.

test@docker-test01:~$ docker help

Usage:  docker COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/home/test/.docker")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default "/home/test/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default "/home/test/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default "/home/test/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  config      Manage Docker configs
  container   Manage containers
  image       Manage images
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  secret      Manage Docker secrets
  service     Manage services
  swarm       Manage Swarm
  system      Manage Docker
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Run 'docker COMMAND --help' for more information on a command.
test@docker-test01:~$

 

docker help Command 정리

docker $command $option  형식으로 사용합니다.

docker attach

Attach local standard input, output, and error streams to a running container

official page doc: https://docs.docker.com/engine/reference/commandline/attach/#override-the-detach-sequence

docker attach test1

test@docker-test02:~$ docker run -d --name topdemo ubuntu /usr/bin/top -b
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
1be7f2b886e8: Pull complete
6fbc4a21b806: Pull complete
c71a6f8e1378: Pull complete
4be3072e5a37: Pull complete
06c6d2f59700: Pull complete
Digest: sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696
Status: Downloaded newer image for ubuntu:latest
ce15a2b8e919ab37b60113189f8c2547718fcbabeecce34224f3695b611e7bfe
test@docker-test02:~$


docker attach 실행 
test@docker-test02:~$ docker attach topdemo


top - 09:55:13 up  1:40,  0 users,  load average: 0.08, 0.05, 0.01
Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.7 us,  0.7 sy,  0.0 ni, 98.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   998340 total,   247164 free,   160772 used,   590404 buff/cache
KiB Swap:  1048572 total,  1042460 free,     6112 used.   638368 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
     1 root      20   0   36532   3064   2704 R   0.0  0.3   0:00.03 top

top - 09:55:16 up  1:40,  0 users,  load average: 0.08, 0.05, 0.01
Tasks:   1 total,   1 running,   0 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :   998340 total,   247164 free,   160772 used,   590404 buff/cache
KiB Swap:  1048572 total,  1042460 free,     6112 used.   638368 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
     1 root      20   0   36532   3064   2704 R   0.0  0.3   0:00.03 top

 

docker attach test2

test@docker-test02:~$ docker run --name ssh-server -d -p 12341:22 -v /home/test/ftp:/home/test/ftp ssh-server
test@docker-test02:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
210ec4045be4        ssh-server          "/usr/sbin/sshd -D"   2 hours ago         Up 2 seconds        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~$
test@docker-test02:~$ docker attach 210ec4045be4

docker attach 커맨드를 이용하여 ssh-server 컨테이너에 접속을 하였지만 접속이 안되는것처럼 보입니다.??

docker 명령어 입력마지막 부분에 /bin/bash 를 입력 하지 않을경우 위와같이 접속만 되어 있습니다.

Ctrl+\ 를 입력하여 attach를 종료 합니다.

종료후 아래와 같이 컨테이너가 종료 합니다.

test@docker-test02:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
test@docker-test02:~$

Ctrl+ p q 입력시 아래와 같이 컨테이너 실행상태에서 나올수 있습니다.

test@docker-test02:~/ssh-server$ docker attach ssh-server


read escape sequence
test@docker-test02:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
7576cad72333        ssh-server          "/usr/sbin/sshd -D"   2 minutes ago       Up 2 minutes        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/ssh-server$

 

docker attach 로 컨테이너에 접속하기 위해서는 -d -it 옵션을 사용해야 합니다.

test@docker-test02:~$ docker run --name test -d -it debian
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
3e731ddb7fc9: Pull complete
Digest: sha256:4fcd8c0b6f5e3bd44a3e63be259fd0c038476d432953d449ef34aedf16def331
Status: Downloaded newer image for debian:latest
3fd41406c5968d8e3c5fd56903a23d6de4d88b230bdf69cff9b3e13ceb8fd213
test@docker-test02:~$ docker attach test
root@3fd41406c596:/#

-d 컨테이너를 생성하여 백그라운드에서 실행
-i 컨테이너 표준입력 열기
-t tty사용

 

docker build

Build an image from a Dockerfile

official page doc: https://docs.docker.com/engine/reference/commandline/build/

docker build test

test@docker-test02:~/nginx$ vi Dockerfile
test@docker-test02:~/nginx$ docker build --tag nginx .
~중략
test@docker-test02:~/nginx$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              80889b2672a1        50 seconds ago      208MB

Dockerfile 작성후 image 생성시 사용 합니다.

–tag 옵션으로 image의 tag를 생성 할수 있습니다.

 

docker commit

Create a new image from a container’s changes

official page doc: https://docs.docker.com/engine/reference/commandline/commit/

docker commit test / git install

test@docker-test02:~/nginx$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
7576cad72333        ssh-server          "/usr/sbin/sshd -D"   32 minutes ago      Up 32 minutes       0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/nginx$ docker exec -it ssh-server /bin/bash
root@7576cad72333:/# apt-get install -y git
~중략
exit 를 입력한후 컨테이너에서 빠져 나옵니다.

test@docker-test02:~/nginx$ docker commit ssh-server ssh-server:git
sha256:64f7265d353e9a5a1fdb021c54205ffaae73ec0bd43a3f1cdf5cba510a3da93b
test@docker-test02:~/nginx$
test@docker-test02:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          git                 64f7265d353e        44 seconds ago      281MB

 

docker run 으로 실행후 git 명령어 실행

test@docker-test02:~$ docker run -it -d ssh-server:git /bin/bash
5da63c65e0a36398a78a64d7199008c779ad20dd7cf31947fd776928475316ee
test@docker-test02:~$ docker exec -it ssh-server:git /bin/bash
Error: No such container: ssh-server:git
test@docker-test02:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5da63c65e0a3        ssh-server:git      "/bin/bash"         24 seconds ago      Up 24 seconds       22/tcp              quirky_hamilton
test@docker-test02:~$ docker exec -it 5da63c65e0a3 /bin/bash
root@5da63c65e0a3:/# git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects

docker commit 의 경우 컨테이너의 변경 사항을 새로운 이미지로 만드는 작업 이라고 보시면 됩니다.

 

docker cp

Copy files/folders between a container and the local filesystem

official page doc: https://docs.docker.com/engine/reference/commandline/cp/

docker cp test

ex) docker cp $컨테이너이름:$경로 $host경로

test@docker-test:~/ftp-server$ docker cp ftpd:/etc/pure-ftpd/pureftpd.passwd /home/test/ftp-server/
test@docker-test:~/ftp-server$ ll
total 24
drwxrwxr-x 4 test test 4096 Feb 20 20:13 ./
drwxr-xr-x 4 test test 4096 Feb 19 21:43 ../
-rw-rw-r-- 1 test test  459 Feb 19 22:17 docker-compose.yml
drwxrwxr-x 2 test test 4096 Feb 19 22:41 pure-ftpd/
-rw-rw-r-- 1 test test   76 Feb 19 22:41 pureftpd.passwd
drwxrwxr-x 2 test test 4096 Feb 19 22:17 ssh-server/
test@docker-test:~/ftp-server$

docker cp의 경우 컨테이너의 파일을 카피 할때 사용 합니다.

 

docker create

Create a new container

official page doc: https://docs.docker.com/engine/reference/commandline/create/#specify-isolation-technology-for-container-isolation

docker create test

test@docker-test02:~/ssh-server$ docker create -i -t --name web-server httpd /bin/bash
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
4176fe04cefe: Pull complete
d6c01cf91b98: Pull complete
b7066921647a: Pull complete
643378aaba88: Pull complete
3c51f6dc6a3b: Pull complete
4f25e420c4cc: Pull complete
ccdbe37da15c: Pull complete
Digest: sha256:6e61d60e4142ea44e8e69b22f1e739d89e1dc8a2764182d7eecc83a5bb31181e
Status: Downloaded newer image for httpd:latest
c148af581e62e60f10bdf936953887c7c7bc8f812c1de722b7520550f5550ab2
test@docker-test02:~/ssh-server$
test@docker-test02:~/ssh-server$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          git                 64f7265d353e        16 minutes ago      281MB
nginx               latest              80889b2672a1        38 minutes ago      208MB
ssh-server          latest              da649966e69c        About an hour ago   206MB
httpd               latest              01154c38b473        5 days ago          177MB

run 명령어의 경우 컨테이너를 만들고 실행하지만 create 의 경우 컨테이너 생성만 하며 실행하지 않습니다.

 

docker diff

Inspect changes to files or directories on a container’s filesystem

official page doc: https://docs.docker.com/engine/reference/commandline/diff/

docker diff test

test@docker-test01:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
4a9c504e3fc0        6aa9f4528408        "/usr/sbin/sshd -D"   3 hours ago         Up 3 hours          0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~$ docker diff 4a9c504e3fc0
C /home/test
A /home/test/.cache
A /home/test/.cache/motd.legal-displayed
A /home/test/ftp
C /run
A /run/motd.dynamic
A /run/sshd.pid
C /run/utmp
C /var/log/lastlog
C /var/log/wtmp
test@docker-test01:~$

diff 명령어로 컨테이너에서 변경된 파일을 확인 할수 있습니다.

A 추가된 파일 / D 삭제된 파일 / C 변경된 파일

 

docker events

Get real time events from the server

official page doc: https://docs.docker.com/engine/reference/commandline/events/

docker events test

테스트를 위하여 2개의 터미널이 필요합니다.

터미널1 

test@docker-test01:~$ docker events

 

터미널2

test@docker-test01:~$ docker start ssh-server
ssh-server
test@docker-test01:~$

 

ssh-server 컨테이너 실행후

터미널1

test@docker-test01:~$ docker events


2018-02-20T20:29:20.559545172+09:00 network connect e6379e085e70251ff6d3aed56b526f0fac2d5cb35a62125ec35f9db043f88013 (container=4a9c504e3fc066c451c037b35041b1308e181b121cd54b3f2fea28b703c98276, name=bridge, type=bridge)
2018-02-20T20:29:20.825386119+09:00 container start 4a9c504e3fc066c451c037b35041b1308e181b121cd54b3f2fea28b703c98276 (image=ssh-server, name=ssh-server)

리얼타임으로 이벤트를 확인할수 있습니다.

 

docker exec

Run a command in a running container

official page doc: https://docs.docker.com/engine/reference/commandline/exec/

docker exec test

test@docker-test02:~$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
5da63c65e0a3        ssh-server:git      "/bin/bash"         31 minutes ago      Up 31 minutes       22/tcp              quirky_hamilton
test@docker-test02:~$ docker exec -it 5da63c65e0a3 /bin/bash
root@5da63c65e0a3:/#

docker exec는 실행중인 컨테이너에 접속할때 사용합니다.

 

docker export

Export a container’s filesystem as a tar archive

official page doc: https://docs.docker.com/engine/reference/commandline/export/

docker export test

test@docker-test02:~$ docker export ssh-server > ./ssh-server.tar
test@docker-test02:~$ ls
Dockerfile  ftp  nginx  ssh-server  ssh-server.tar
test@docker-test02:~$

컨테이너 백업시 사용합니다.

 

docker history

Show the history of an image

official page doc: https://docs.docker.com/engine/reference/commandline/history/

docker history test

test@docker-test01:~$ docker history ssh-server
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
7497e5839808        4 hours ago         /usr/sbin/sshd -D                               293kB
6aa9f4528408        4 hours ago         /bin/sh -c #(nop)  CMD ["/usr/sbin/sshd" "-D…   0B
42ebcc23b6f4        4 hours ago         /bin/sh -c #(nop)  EXPOSE 22                    0B
6e1b50e948a4        4 hours ago         /bin/sh -c echo "export VISIBLE=now" >> /etc…   594B
6520e9fab9c9        4 hours ago         /bin/sh -c #(nop)  ENV NOTVISIBLE=in users p…   0B
559b0ee95543        4 hours ago         /bin/sh -c apt-get update && apt-get install…   94.6MB
f98d236d73eb        4 hours ago         /bin/sh -c #(nop)  MAINTAINER Sven Dowideit …   0B
0458a4468cbc        3 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/bash"]            0B
<missing>           3 weeks ago         /bin/sh -c mkdir -p /run/systemd && echo 'do…   7B
<missing>           3 weeks ago         /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$…   2.76kB
<missing>           3 weeks ago         /bin/sh -c rm -rf /var/lib/apt/lists/*          0B
<missing>           3 weeks ago         /bin/sh -c set -xe   && echo '#!/bin/sh' > /…   745B
<missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:a3344b835ea6fdc56…   112MB
test@docker-test01:~$

image history 를 출력합니다.

 

docker images

List images

official page doc: https://docs.docker.com/engine/reference/commandline/images/

docker images test

test@docker-test:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ftp/pure-ftpd       14.04               75c73f446597        22 hours ago        435MB
<none>              <none>              6a6688153895        23 hours ago        435MB
ssh-server          latest              1e5966c6bdf0        23 hours ago        206MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
ubuntu              14.04               dc4491992653        3 weeks ago         222MB
test@docker-test:~$

docker image 정보를 출력합니다.

 

docker import

Import the contents from a tarball to create a filesystem image

official page doc: https://docs.docker.com/engine/reference/commandline/import/

docker import test

test@docker-test01:~$ cat ssh-server.tar | docker import - ssh-server
sha256:3f3f63beac844f0c2e806f2a4cc22457dd612abefd8417eabd9dbd1de5a92ecc
test@docker-test01:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              3f3f63beac84        2 seconds ago       253MB
test@docker-test01:~$

export 한 tar 파일로 images 를 생성 합니다.

 

docker info

Display system-wide information

official page doc: https://docs.docker.com/engine/reference/commandline/info/

docker info test

test@docker-test02:~$ docker info
Containers: 5
 Running: 1
 Paused: 0
 Stopped: 4
Images: 21
Server Version: 18.02.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9b55aab90508bd389d7654c4baf173a981477d55
runc version: 9f9c96235cc97674e935002fc3d78361b696a69e
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-62-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 974.9MiB
Name: docker-test02
ID: QAGI:PK3E:CG7L:3D73:UQJ3:UP4P:LZTZ:2PZP:3GBS:ORWS:FL36:EWWJ
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No swap limit support
test@docker-test02:~$

docker 정보를 출력 합니다.

 

docker inspect

Return low-level information on Docker objects

official page doc: https://docs.docker.com/engine/reference/commandline/inspect/

docker inspect test

test@docker-test01:~$ docker inspect ssh-server
[
    {
        "Id": "sha256:3f3f63beac844f0c2e806f2a4cc22457dd612abefd8417eabd9dbd1de5a92ecc",
        "RepoTags": [
            "ssh-server:latest"
        ],
        "RepoDigests": [],
        "Parent": "",
        "Comment": "Imported from -",
        "Created": "2018-02-20T11:52:52.28045397Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "18.02.0-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 253405442,
        "VirtualSize": 253405442,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/merged",
                "UpperDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/diff",
                "WorkDir": "/var/lib/docker/overlay2/6c47d31e2d5ff00a9fb4676f595a33fd45afaa6592c50cb069d1777df6bd4616/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:3f277380640a29287b45210df57c9c6ea7711a363a593128e9c0c2fec50b91b8"
            ]
        },
        "Metadata": {
            "LastTagTime": "2018-02-20T20:52:52.283195652+09:00"
        }
    }
]
test@docker-test01:~$

image 정보 확인시 사용합니다.

이미지ID / 생성일 / Docker 버전 / 이미지 생성자 / CPU 확인할수 있습니다.

 

docker kill

Kill one or more running containers

official page doc: https://docs.docker.com/engine/reference/commandline/kill/

docker kill test2

test@docker-test:~$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
74a223f30014        ftp/pure-ftpd:14.04   "/bin/sh -c '/usr/sb…"   About an hour ago   Up About an hour    0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
b76d16b5f4b4        ssh-server            "/usr/sbin/sshd -D"      About an hour ago   Up About an hour    0.0.0.0:12341->22/tcp                                      ssh-server
test@docker-test:~$ docker kill ssh-server
ssh-server
test@docker-test:~$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
74a223f30014        ftp/pure-ftpd:14.04   "/bin/sh -c '/usr/sb…"   About an hour ago   Up About an hour    0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
test@docker-test:~$

 

docker kill test2

test@docker-test:~/ftp-server$ docker kill ftpd ssh-server
ftpd
ssh-server
test@docker-test:~/ftp-server$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
test@docker-test:~/ftp-server$

docker kill 명령어로 컨테이너에 kill 시그널을 보낼수 있습니다.

하나 또는 하나이상의 컨테이를 kill 시킬수 있습니다.

 

docker load

Load an image from a tar archive or STDIN

official page doc: https://docs.docker.com/engine/reference/commandline/load/

docker load test

test@docker-test02:~$ docker load -i ssh-server.tar
3f277380640a: Loading layer [==================================================>]  264.1MB/264.1MB
Loaded image: ssh-server:latest
test@docker-test02:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              3f3f63beac84        26 minutes ago      253MB
test@docker-test02:~$

tar -> docker image로 변환 합니다.?

 

docker login

Log in to a Docker registry

official page doc: https://docs.docker.com/engine/reference/commandline/login/

//차후테스트

docker 저장소에 로그인합니다.

 

docker logout

Log out from a Docker registry

official page doc: https://docs.docker.com/engine/reference/commandline/logout/

//차후테스트

docker 저장소에서 로그아웃합니다.

 

docker logs

Fetch the logs of a container

official page doc: https://docs.docker.com/engine/reference/commandline/logs/

//차후테스트

컨테이너 로그를 출력합니다.

 

docker pause

Pause all processes within one or more containers

official page doc: https://docs.docker.com/engine/reference/commandline/pause/

docker pause test

test@docker-test01:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   3 minutes ago       Up 3 minutes        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~/ssh-server$ docker pause ssh-server
ssh-server
test@docker-test01:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                  PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   6 minutes ago       Up 6 minutes (Paused)   0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~/ssh-server$

컨테이너 내의 모든 프로세스 일시정지

 

docker port

List port mappings or a specific mapping for the container

official page doc: https://docs.docker.com/engine/reference/commandline/port/

docker port test

test@docker-test01:~/ssh-server$ docker port ssh-server
22/tcp -> 0.0.0.0:12341
test@docker-test01:~/ssh-server$

특정컨테이너의 port 연결 정보를 확인 합니다.

 

docker ps

List containers

official page doc: https://docs.docker.com/engine/reference/commandline/ps/

docker ps test

test@docker-test01:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   12 minutes ago      Up 12 minutes       0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~/ssh-server$

컨테이너 정보를 확인 합니다.

 

docker pull

Pull an image or a repository from a registry

official page doc: https://docs.docker.com/engine/reference/commandline/pull/

docker pull test

test@docker-test01:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              f1c017c1bfcf        34 minutes ago      206MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
test@docker-test01:~$ docker pull ubuntu:latest
latest: Pulling from library/ubuntu
Digest: sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696
Status: Downloaded newer image for ubuntu:latest
test@docker-test01:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              f1c017c1bfcf        34 minutes ago      206MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
ubuntu              latest              0458a4468cbc        3 weeks ago         112MB
test@docker-test01:~$

images 저장소에서 image를 down 합니다.

 

docker push

Push an image or a repository to a registry

official page doc: https://docs.docker.com/engine/reference/commandline/push/

docker push test

//차후테스트

docker hub 에 이미지를 등록합니다.

 

docker rename

Rename a container

official page doc: https://docs.docker.com/engine/reference/commandline/rename/

docker rename test

test@docker-test01:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   23 minutes ago      Up 23 minutes       0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~$ docker rename ssh-server sshd
test@docker-test01:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   23 minutes ago      Up 23 minutes       0.0.0.0:12341->22/tcp   sshd
test@docker-test01:~$

컨테이너의 이름을 변경 합니다.

 

docker restart

Restart one or more containers

official page doc: https://docs.docker.com/engine/reference/commandline/restart/

docker restart test

test@docker-test01:~$ docker restart sshd
sshd
test@docker-test01:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
d2269ec836fd        ssh-server          "/usr/sbin/sshd -D"   25 minutes ago      Up 3 seconds        0.0.0.0:12341->22/tcp   sshd
test@docker-test01:~$

컨테이너를 재시작 합니다.

 

docker rm

Remove one or more containers

official page doc: https://docs.docker.com/engine/reference/commandline/rm/

docker rm test

test@docker-test01:~$ docker stop sshd
sshd
test@docker-test01:~$ docker rm sshd
sshd
test@docker-test01:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
test@docker-test01:~$

컨테이너를 삭제 합니다.

 

docker rmi

Remove one or more images

official page doc: https://docs.docker.com/engine/reference/commandline/rmi/

docker rmi test

test@docker-test01:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              0458a4468cbc        3 weeks ago         112MB
test@docker-test01:~$ docker rmi 0458a4468cbc
Untagged: ubuntu:latest
Untagged: ubuntu@sha256:e27e9d7f7f28d67aa9e2d7540bdc2b33254b452ee8e60f388875e5b7d9b2b696
Deleted: sha256:0458a4468cbceea0c304de953305b059803f67693bad463dcbe7cce2c91ba670
Deleted: sha256:77e6ddba346d8ad1e436256f6373dede5af4002006981b7d4116c561c759cefa
Deleted: sha256:8db758ab2fdb54da0aec53aeac876934337e6170f5a8c8872b3d4171e3d465b7
Deleted: sha256:a7fc6b405fe8ef71edfa6163d1dc9f1cb1df426049eefaa7d388e9df21a061ad
Deleted: sha256:5a3e35538f7f2e2727c8ac92f08c30002b9e8a77737de0dab91244344d59f69b
Deleted: sha256:ff986b10a018b48074e6d3a68b39aad8ccc002cdad912d4148c0f92b3729323e
test@docker-test01:~$

images 를 삭제 합니다.

 

docker run

Run a command in a new container

official page doc: https://docs.docker.com/engine/reference/run/

docker run test

test@docker-test02:~/ssh-server$ docker run --name ssh-server -d -p 12341:22 -v /home/test/ftp:/home/test/ftp ssh-server
eef4f1176e28dca616b2b4ba7a3b59c6722f8a7f8a3d079c901b31c8a00f60ba
test@docker-test02:~/ssh-server$

컨테이너를 실행 합니다.

 

docker save

Save one or more images to a tar archive (streamed to STDOUT by default)

official page doc: https://docs.docker.com/engine/reference/commandline/save/

docker save test

test@docker-test01:~$ docker save -o ssh-server.tar ssh-server
test@docker-test01:~$ ls
ftp  ssh-server  ssh-server.tar
test@docker-test01:~$

docker images 를 tar 파일로 저장합니다.

 

docker search

Search the Docker Hub for images

official page doc: https://docs.docker.com/engine/reference/commandline/search/

docker search test

test@docker-test01:~$ docker search nginx
NAME                                                   DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                                                  Official build of Nginx.                        7971                [OK]
jwilder/nginx-proxy                                    Automated Nginx reverse proxy for docker con…   1276                                    [OK]
richarvey/nginx-php-fpm                                Container running Nginx + PHP-FPM capable of…   517                                     [OK]
jrcs/letsencrypt-nginx-proxy-companion                 LetsEncrypt container to use with nginx as p…   312                                     [OK]
kong                                                   Open-source Microservice & API Management la…   158                 [OK]
webdevops/php-nginx                                    Nginx with PHP-FPM                              97                                      [OK]
kitematic/hello-world-nginx                            A light-weight nginx container that demonstr…   95
bitnami/nginx                                          Bitnami nginx Docker Image                      44                                      [OK]
zabbix/zabbix-web-nginx-mysql                          Zabbix frontend based on Nginx web-server wi…   43                                      [OK]
linuxserver/nginx                                      An Nginx container, brought to you by LinuxS…   33
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5   ubuntu-16-nginx-php-phpmyadmin-mysql-5          26                                      [OK]
tobi312/rpi-nginx                                      NGINX on Raspberry Pi / armhf                   17                                      [OK]
wodby/drupal-nginx                                     Nginx for Drupal container image                9                                       [OK]
webdevops/nginx                                        Nginx container                                 8                                       [OK]
blacklabelops/nginx                                    Dockerized Nginx Reverse Proxy Server.          8                                       [OK]
nginxdemos/nginx-ingress                               NGINX Ingress Controller for Kubernetes         8
centos/nginx-18-centos7                                Platform for running nginx 1.8 or building n…   6
1science/nginx                                         Nginx Docker images that include Consul Temp…   4                                       [OK]
nginxdemos/hello                                       NGINX webserver that serves a simple page co…   3                                       [OK]
pebbletech/nginx-proxy                                 nginx-proxy sets up a container running ngin…   2                                       [OK]
behance/docker-nginx                                   Provides base OS, patches and stable nginx f…   2                                       [OK]
centos/nginx-112-centos7                               Platform for running nginx 1.12 or building …   2
travix/nginx                                           NGinx reverse proxy                             1                                       [OK]
toccoag/openshift-nginx                                Nginx reverse proxy for Nice running on same…   1                                       [OK]
mailu/nginx                                            Mailu nginx frontend                            0                                       [OK]
test@docker-test01:~$

Docker 이미지를 검색 합니다.

 

docker start

Start one or more stopped containers

official page doc: https://docs.docker.com/engine/reference/commandline/start/

docker start test

test@docker-test02:~/ssh-server$ docker ps -a
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                     PORTS               NAMES
eef4f1176e28        ssh-server          "/usr/sbin/sshd -D"   16 minutes ago      Exited (0) 3 seconds ago                       ssh-server
test@docker-test02:~/ssh-server$ docker start ssh-server
ssh-server
test@docker-test02:~/ssh-server$

정지된 컨테이너를 실행 합니다.

 

docker stats

Display a live stream of container(s) resource usage statistics

official page doc: https://docs.docker.com/engine/reference/commandline/stats/

docker stats test

test@docker-test02:~/ssh-server$ docker stats ssh-server

CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT   MEM %               NET I/O             BLOCK I/O           PIDS
eef4f1176e28        ssh-server          0.00%               716KiB / 974.9MiB   0.07%               648B / 0B           0B / 0B             1

컨테이너의 자원 사용량을 확인 합니다.

 

 

docker stop

Stop one or more running containers

official page doc: https://docs.docker.com/engine/reference/commandline/stop/

docker stop test

test@docker-test02:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
eef4f1176e28        ssh-server          "/usr/sbin/sshd -D"   20 minutes ago      Up 4 minutes        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/ssh-server$ docker stop ssh-server
ssh-server
test@docker-test02:~/ssh-server$

컨테이너를 정지합니다.

 

 

 

 

docker tag

Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

official page doc: https://docs.docker.com/engine/reference/commandline/tag/

docker tag test

test@docker-test02:~/ssh-server$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              8ee8efce9736        40 minutes ago      206MB
<none>              <none>              3f3f63beac84        2 hours ago         253MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
test@docker-test02:~/ssh-server$ docker tag 0458a4468cbc nginx-test
test@docker-test02:~/ssh-server$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              8ee8efce9736        41 minutes ago      206MB
<none>              <none>              3f3f63beac84        2 hours ago         253MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
nginx-test          latest              0458a4468cbc        3 weeks ago         112MB
test@docker-test02:~/ssh-server$

test@docker-test02:~/ssh-server$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              8ee8efce9736        45 minutes ago      206MB
<none>              <none>              3f3f63beac84        2 hours ago         253MB
nginx-test          0.1                 0458a4468cbc        3 weeks ago         112MB
nginx-test          latest              0458a4468cbc        3 weeks ago         112MB
ubuntu              16.04               0458a4468cbc        3 weeks ago         112MB
test@docker-test02:~/ssh-server$

 

 

docker top

Display the running processes of a container

official page doc: https://docs.docker.com/engine/reference/commandline/top/

docker top test

test@docker-test02:~/ssh-server$ docker top ssh-server
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                17478               17460               0                   23:23               ?                   00:00:00            /usr/sbin/sshd -D
test@docker-test02:~/ssh-server$

컨테이너의 실행중인 프로세스를 표시합니다.

 

 

docker unpause

Unpause all processes within one or more containers

official page doc: https://docs.docker.com/engine/reference/commandline/unpause/

docker unpause test

test@docker-test02:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS                  PORTS                   NAMES
eef4f1176e28        ssh-server          "/usr/sbin/sshd -D"   About an hour ago   Up 2 minutes (Paused)   0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/ssh-server$ docker unpause ssh-server
ssh-server
test@docker-test02:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
eef4f1176e28        ssh-server          "/usr/sbin/sshd -D"   About an hour ago   Up 2 minutes        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/ssh-server$

docker pause 상태에서 복귀 합니다.

 

 

docker update

Update configuration of one or more containers

official page doc: https://docs.docker.com/engine/reference/commandline/update/

docker update test

//차후테스트

컨테이너 설정을 업데이트 합니다.

 

 

docker version

Show the Docker version information

official page doc: https://docs.docker.com/engine/reference/commandline/version/

docker version test

test@docker-test01:~$ docker version
Client:
 Version:       18.02.0-ce
 API version:   1.36
 Go version:    go1.9.3
 Git commit:    fc4de44
 Built: Wed Feb  7 21:16:33 2018
 OS/Arch:       linux/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:      18.02.0-ce
  API version:  1.36 (minimum version 1.12)
  Go version:   go1.9.3
  Git commit:   fc4de44
  Built:        Wed Feb  7 21:15:05 2018
  OS/Arch:      linux/amd64
  Experimental: false
test@docker-test01:~$

docker version 을 출력합니다.

 

docker wait

Block until one or more containers stop, then print their exit codes

official page doc: https://docs.docker.com/engine/reference/commandline/wait/

docker wait test

터미널 1

test@docker-test02:~/ssh-server$ docker wait ssh-server

docker wait ssh-server 명령어를 실행후 대기합니다.

 

터미널2 

test@docker-test02:~$ docker kill ssh-server
ssh-server

 

터미널1 

test@docker-test02:~/ssh-server$ docker wait ssh-server
137
test@docker-test02:~/ssh-server$

docker wait 실행시 컨테이너가 종료할때까지 대기하다가 종료 코드를 출력 합니다.

 

 

 

 

Container Backup and Recovery

컨테이너를 tar 파일로 저장

 

Container Backup

docker-test01 Server 에서 ssh-server.tar 파일 생성

test@docker-test01:~$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
4a9c504e3fc0        ssh-server          "/usr/sbin/sshd -D"   8 minutes ago       Up About a minute   0.0.0.0:12341->22/tcp   ssh-server
test@docker-test01:~$

docker commit 
test@docker-test01:~$ docker commit -p 4a9c504e3fc0 ssh-server
sha256:7497e5839808a3d16aa4e665250b0b56c2c2b68316389583a8dc5b3a369a0e1d
test@docker-test01:~$

docker save
test@docker-test01:~$ docker save -o ssh-server.tar ssh-server

 

Container Recovery

docker-test02 Server 에서 docker load 명령어를 이용하여 ssh-server.tar 파일을 load

test@docker-test02:~/ssh-server$ docker load -i ssh-server.tar
ff986b10a018: Loading layer  115.7MB/115.7MB
9c7183e0ea88: Loading layer  15.87kB/15.87kB
c98ef191df4b: Loading layer  14.85kB/14.85kB
92914665e7f6: Loading layer  5.632kB/5.632kB
6f4ce6b88849: Loading layer  3.072kB/3.072kB
45c63a717468: Loading layer  98.94MB/98.94MB
6a99d630753a: Loading layer  3.072kB/3.072kB
4974e070de92: Loading layer  302.1kB/302.1kB
Loaded image: ssh-server:latest
test@docker-test02:~/ssh-server$
image 확인
test@docker-test02:~/ssh-server$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssh-server          latest              7497e5839808        11 minutes ago      207MB
test@docker-test02:~/ssh-server$

 

ssh-server 실행

test@docker-test02:~/ssh-server$ mkdir ~/ftp
test@docker-test02:~/ssh-server$ docker run --name ssh-server -d -p 12341:22 -v /home/test/ftp:/home/test/ftp ssh-server
210ec4045be4be565689aebcb00d5d7171f954efdb1bf493563a7669a74b7400
test@docker-test02:~/ssh-server$ docker ps
CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                   NAMES
210ec4045be4        ssh-server          "/usr/sbin/sshd -D"   3 seconds ago       Up 2 seconds        0.0.0.0:12341->22/tcp   ssh-server
test@docker-test02:~/ssh-server$

 

 

docker-compose pure-ftpd ssh-server 구성

 

참고사항:

pure-ftpd ubuntu 14.04

ssh-server ubuntu 16.04

vmware NAT 환경시 문제가 생길수 있습니다. Bridge 환경으로 테스트 하시기 바랍니다.

 

Github

test@docker-test:~$ git clone https://github.com/visualwork/Docker-test.git

/Docker-test/test04 에 있습니다. 🙂

 

디렉토리 구조

ftp-server$ tree

├── docker-compose.yml
├── pure-ftpd
│       ├── Dockerfile
│       └── pureftpd.passwd
└── ssh-server
    └── Dockerfile

 

docker-compose 를 구성하기 위하여 디렉토리를 생성 합니다. 

test@docker-test:~$ mkdir ftp-server
test@docker-test:~$ cd ftp-server/
test@docker-test:~/ftp-server$ mkdir pure-ftpd
test@docker-test:~/ftp-server$ mkdir ssh-server
test@docker-test:~/ftp-server$ sudo mkdir /ftp-data
test@docker-test:~/ftp-server$ sudo chown test:test /ftp-data/

 

docker-compose.yml 파일 생성

test@docker-test:~/ftp-server$ pwd
/home/test/ftp-server
test@docker-test:~/ftp-server$ vi docker-compose.yml

version: '3'

services:
  pure-ftpd:
    build:
      context: pure-ftpd
    image: ftp/pure-ftpd:14.04
    container_name: ftpd
    ports:
      - "21:21"
      - "20000-20099:20000-20099"
    volumes:
      - "/ftp-data:/home/ftp"
    restart: always

  ssh-server:
    build:
      context: ssh-server
    image: ssh-server
    container_name: ssh-server
    ports:
      - "12341:22"
    volumes:
      - "/ftp-data:/home/test/ftp:ro"
    restart: always

 

 

ssh-server Dockerfile 생성

test@docker-test:~/ftp-server$ cd ssh-server/
test@docker-test:~/ftp-server/ssh-server$ vi Dockerfile
FROM ubuntu:16.04
MAINTAINER Sven Dowideit <SvenDowideit@docker.com>
 
#RUN apt-get update && apt-get install -y openssh-server
RUN apt-get update && apt-get install -y openssh-server \
&& mkdir /var/run/sshd \
&& useradd -ms /bin/bash test \
&& sed -ie 's/test:!/test:\$6\$pIPlIFrg\$WZRTmOoouwD6L\/IDgz8fw97agQjdeXticOJyayjUYwmiuNKkJE92rBtr0XDXhVE4rSi9PkWv8rtnA0rCuR6ts\//g' /etc/shadow \
&& sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
 
#COPY data/* /.ROOT/
 
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
 
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

test user 의 패스워드는 test1234 입니다.

 

pure-ftpd Dockerfile 생성

FROM ubuntu:14.04

MAINTAINER test@test

RUN apt-get update && \
apt-get install pure-ftpd openssl libpam-dev libcap2-dev libldap2-dev libmysqlclient-dev libmysqlclient15-dev libpq-dev libssl-dev po-debconf dpkg-dev debhelper -y

RUN mkdir /tmp/pure-ftpd/ && \
        cd /tmp/pure-ftpd/ && \
        apt-get source pure-ftpd && \
        cd pure-ftpd-* && \
        sed -i '/^optflags=/ s/$/ --without-capabilities/g' ./debian/rules && \
        dpkg-buildpackage -b -uc
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd-common*.deb
RUN apt-get -y install openbsd-inetd
RUN dpkg -i /tmp/pure-ftpd/pure-ftpd_*.deb
RUN apt-mark hold pure-ftpd pure-ftpd-common
RUN cd /etc/pure-ftpd && \
adduser ftpd-data && \
mkdir /home/ftp && \
chown ftpd-data:ftpd-data -R /home/ftp && \
echo yes > ./conf/ChrootEveryone && \
echo yes > ./conf/DontResolve && \
echo yes > ./conf/NoChmod && \
echo yes > ./conf/ProhibitDotFilesWrite && \
echo yes > ./conf/CustomerProof && \
echo '20000 20099' > ./conf/PassivePortRange && \
echo ',21' > ./conf/Bind && \
echo '2' > ./conf/TLS && \
openssl req -x509 -nodes -days 1825 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem -subj "/C=KR/ST=SouthKorea/L=Seoul/O=test.com/OU=IT Department/CN=ftp.test.com"
ADD pureftpd.passwd /etc/pure-ftpd/
RUN pure-pw mkdb
RUN ln -sf /dev/stdout /var/log/pure-ftpd/transfer.log
CMD /usr/sbin/pure-ftpd -l puredb:/etc/pure-ftpd/pureftpd.pdb -x -u 30 -H -S ,21 -O clf:/var/log/pure-ftpd/transfer.log -Z -A -p 20000:20099 -E -R -8 UTF-8 -Y 2
EXPOSE 21/tcp 20000-20099/tcp

 

pureftpd.passwd file 생성

test@docker-test:~/ftp-server/pure-ftpd$ pwd
/home/test/ftp-server/pure-ftpd
test@docker-test:~/ftp-server/pure-ftpd$ vi pureftpd.passwd
test:$1$P4DB31/0$iIPf8.YJ6XP6k1zsmQtJq1:1000:1000::/home/ftp/./::::::::::::

(pure-ftpd VirtualUser 생성시 pureftpd.passwd 파일에 계정을 추가 하면 됩니다.)

test / test1234 입니다.

 

ftp-server 실행

test@docker-test:~/ftp-server$ docker-compose up -d --build
test@docker-test:~/ftp-server$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
25725255d655        ftp/pure-ftpd:14.04   "/bin/sh -c '/usr/sb…"   8 seconds ago       Up 6 seconds        0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
b319c9a53cb3        ssh-server            "/usr/sbin/sshd -D"      8 seconds ago       Up 6 seconds        0.0.0.0:12341->22/tcp                                      ssh-server
test@docker-test:~/ftp-server$

 

pure-ftp user 생성시 참고

test@docker-test:~/ftp-server$ docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                      NAMES
6906ee88690b        ftp/pure-ftpd:14.04   "/bin/sh -c '/usr/sb…"   37 seconds ago      Up 35 seconds       0.0.0.0:21->21/tcp, 0.0.0.0:20000-20099->20000-20099/tcp   ftpd
c48bb291d39e        ssh-server            "/usr/sbin/sshd -D"      37 seconds ago      Up 35 seconds       0.0.0.0:12341->22/tcp                                      ssh-server
test@docker-test:~/ftp-server$ docker exec -it 6906ee88690b /bin/bash

root@6906ee88690b:/# pure-pw useradd test1 -u ftpd-data -g ftpd-data -d /home/ftp
Password:
Enter it again:
root@6906ee88690b:/# pure-pw mkdb


root@6906ee88690b:/# cat /etc/pure-ftpd/pureftpd.passwd
test:$1$P4DB31/0$iIPf8.YJ6XP6k1zsmQtJq1:1000:1000::/home/ftp/./::::::::::::
test1:$1$R4VNLgS0$Upx3H9Fky0V/LJ9uNALim.:1000:1000::/home/ftp/./::::::::::::

 

pureftpd.passwd 파일에 user:password 필드로 입력하면 됩니다.

컨테이너의  /etc/pure-ftpd/pureftpd.passwd 파일에서 패스워드를 확인 가능 합니다.

test@docker-test:~/ftp-server/pure-ftpd$ cat pureftpd.passwd
test:$1$P4DB31/0$iIPf8.YJ6XP6k1zsmQtJq1:1000:1000::/home/ftp/./::::::::::::

 

 

filezilla 접속테스트

 

별도로 Test는 진행하지 않았지만 sshfs 로 mount 를 할수 있습니다.

ssh-server port 12341 로 mount 하여 사용할수 있습니다. 🙂