docker cli #01

DevOps 2020. 1. 15. 17:55

$ docker search "ubuntu"

$ docker pull ubuntu:16.04

$ docker pull ubuntu:latest

$ docker images

$ docker run -it -d --name ubuntu16 ubuntu:16.04 /bin/bash        

$ docker run –it -p 8080:80 –v ~/shared_src:/mnt/shared_src --name ubuntu16 ubuntu:16.04 /bin/bash

$ docker start ubuntu16 (sudo docker restart/stop ubuntu16)

$ docker attach ubuntu16

    [docker shell] <Ctrl> + p , <Ctrl> + q

$ docker start ubuntu16

$ docker exec ubuntu16 echo "HelloWorld"

$ docker exec -it ubuntu16 /bin/bash

$ docker rm ubuntu16

$ docker ps -a

 

 

+. Docker logs

$ docker logs ${container id}

$ docker logs --tail 10 ${container id}

$ docker logs -f ${container id}

 

 

+. Commit to image

$ docker tag ${image_id} ${docker_hub_id}/${image_name}:{tag}         -> for docker hub

$ docker tag ${image_id} ${registry_host_ip:port}/${image_name}:{tag} -> for private registry

 

 

 

+. Docker Hub Login & Push

$ docker login –u${user_id}

$ docker push ${docker_hub_id}/${image_name}:{tag}

 

 

 

+. Dockerfile

$ vi Dockerfile

    FROM ubuntu:16.04

    MAINTAINER Foo Bar foo@bar.com

    RUN apt-get update

    RUN apt-get install -y nginx

    RUN echo "daemon off;" >> /etc/nginx/nginx.conf

    RUN chown -R www-data:www-data /var/lib/nginx

    VOLUME ["/opt/docker/src", "/opt/docker/log", "/opt/docker/lib"]

    WORKDIR /etc/nginx

    CMD ["nginx"]

    EXPOSE 80

    EXPOSE 443

$ docker build --tag ubuntu:16.04 .

 

 

 

+. Docker Compose

a. Create empty directory & create 'docker-compose.yml'  

-----------------------------------------------------------------------------------------

    version: '2'

 

    services:

       db:

         image: mysql:5.7

         volumes:

           - db_data:/var/lib/mysql

         restart: always

         environment:

           MYSQL_ROOT_PASSWORD: wordpress

           MYSQL_DATABASE: wordpress

           MYSQL_USER: wordpress

           MYSQL_PASSWORD: wordpress

 

       wordpress:

         depends_on:

           - db

         image: wordpress:latest

         volumes:

           - wp_data:/var/www/html

         ports:

           - "8000:80"

         restart: always

         environment:

           WORDPRESS_DB_HOST: db:3306

           WORDPRESS_DB_PASSWORD: wordpress

    volumes:

        db_data:

        wp_data:

-----------------------------------------------------------------------------------------

 

b. docker-compose up

 

 

 

+. .dockerignore

-----------------------------------------------------------------------------------------

# git

.git

.gitignore

.svn

 

# os-related

.DS_Store

.ipynb_checkpoints

pids

*.pid

*.seed

 

# javascripts

.grunt

.lock-wscript

node_modules

 

# Spring Boot

/src

.pom.xml

/.settings

.classpath

.project

.springBeans

-----------------------------------------------------------------------------------------

 

 

 

+. remove unused volume

docker volume ls -qf "dangling=true" | xargs docker volume rm

 

 

 

+. Runtime Options - docker resource control

$ docker run -it -d --cpus=".5" --memory="256m" --name  ubuntu16_8 ubuntu:16.04 /bin/bash

 

 

+. Docker resource usage monitoring -> glances

 

 

 

 

 

 

 

 

'DevOps' 카테고리의 다른 글

Ping Test for Tomcat AJP connector  (0) 2020.01.15
GitLab with Docker Image official guide (GitLab)  (0) 2020.01.15
Ansible quick start  (0) 2020.01.15
Git cheat sheet #02  (0) 2020.01.15
Git cheat sheet #01  (0) 2020.01.15
블로그 이미지

Melting

,