layout | title | categories | comments | tags | ||
---|---|---|---|---|---|---|
post |
PL00, Docker |
|
true |
|
Back to the previous page|page management
List of posts to read before reading this article
{:.no_toc}
- ToC {:toc}
URL
About image
$ docker search [image]
$ docker pull [image]
$ docker images # same to below
$ docker image ls # same to above
$ docker images -q
$ docker image rm [image]
$ docker commit [origin_container] [new_container]
$ docker run --help
$ docker run [image]
$ docker run [image] [command]
$ docker run -itd [image]
$ docker run --restart=always [image]
$ docker run --name "[container_name]" [image]
$ docker run -itd --restart=always --name "[container_name]" [image] [command]
About container
$ docker exec [container_name] [command]
$ docker ps # same to below
$ docker container ls # same to above
$ docker ps -q
$ docker stop [container_name]
$ docker ps -a
$ docker container ls -a
$ docker rename [old_container_name] [new_container_name]
$ docker rm [container_name]
$ docker start [container_name]
$ docker attach [container_name]
# exit : container be removed after exit
# ctrl + d : container be removed after exit
# ctrl + p, g : container be kept after exit(detach)
$ docker cp [container_name]:[path] [client_path]
$ docker cp [client_path] [container_name]:[path]
$ docker run -v [local_path]:[container_path]
# docker run -v [local_path]:/local_host
$ docker container prune
About resource
$ docker --help
$ docker info
$ docker version
$ docker --version
$ docker-machine ls
$ docker system df
/bin/docker_bash
step0] Create container
$ docker search [image_name]
$ docker pull [image_name]
$ docker run -itd --name [container_name(origin)] [image_name]
$ docker attach [container_name(origin)]
step1] Write shall script in origin ```bash $ cd /bin/ $ vim docker_bash ``` ```bash #!/bin/sh /etc/init.d/xinetd restart export LANGUAGE=ko LC_ALL=ko_KR.UTF-8 bash ``` ```bash ctrl + p, q ```
step2] Commit image file ```bash $ docker commit [container_name(origin)] [image_name(new)] $ docker images ```
step3] Remove origin image file ```bash $ docker stop [container_name(origin)] $ docker rm [container_name(origin)] ```
step4] Create new customized container ```bash $ docker run -itd --restart=always --name [container_name(new)] [image_name(new)] /bin/docker_bash ```
step5] Use new customized container ```bash $ docker attach [container_name(new)] ```
$ curl -sSL https://get.docker.com/ | sh
$ sudo usermod -aG docker [user]
$ sudo reboot
$ docker -v
$ docker pull jupyter/scipy-notebook
$ docker run -p 8888:8888 jupyter/scipy-notebook
$ docker ps # Monitor Running Docker Containers
$ docker stats # Monitor Docker Memory Usage
$ docker restart [Container ID]
Container ID
```bash $ docker stats ``` ![image](https://user-images.githubusercontent.com/52376448/69275264-6e2a3200-0c1f-11ea-8687-18381eb5dce4.png)
$ snap install docker
# Display Docker Hosts Associated with the Running Attached Docker Engine
$ docker-machine ls
$ apt update
$ apt search docker | grep docker.io
# Display Meta-Information for docker.io Package
$ apt policy docker.io
# Remove Previous Installations of docker
$ apt remove docker
# Allow apt to Use a Repository Over HTTPS
$ apt install apt-transport-https ca-certificates curl software-properties.common
# Add Docker’s Official GPG Key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
$ apt-key fingerprint 0EBFCD88
# Add Your System’s Specific Docker Repository
$ add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ apt update
$ apt install -y docker-ce
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ docker version
$ docker help
$ which docker
$ docker run hello-world
$ docker run -it ubuntu /bin/bash
$ docker search httpd
$ docker pull httpd
$ docker run -d -p 80:80 httpd
$ docker ps
$ curl local host
# Launch the File Server Via the Docker Container
$ docker run -v ~:/home -p 5000:8000 python:2.7 python -m SimpleHTTPServer
$ apt install tree
$ mkdir project project/bin project/src project/docker
$ vim bessel.c
// src/bessel.c
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main(void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0(x);
printf("J0(%g) = %.18e\n", x, y);
return 0;
}
$ vim Dockerfile
FROM gcc
LABEL maintainer=@joshuacook
RUN apt-get update && \
apt-get install -y \
gsl-bin \
libgsl0-dbg \
libgsl0-dev \
libgsl0ldbl
# Build the gsl Docker Image
$ docker build -t [Image_name] docker
# Display Local Docker Images
$ docker images
$ docker run -v 'pwd':/home gsl gcc -I /usr/include/ -L /usr/lib/ -lgsl -lgslcblas /home/src/bessel.c -o /home/bin/bessel
$ docker run -v 'pwd':/home gsl_image /home/bin/bessel
# Launch ipython Using the jupyter/scipy-notebook Image
$ docker run -it jupyter/scipy-notebook ipython
# Display Docker Usage
$ docker
# Display Docker System Info
$ docker info
# Pull the alpine Docker Image
$ docker pull alpine
# Run an Interactive Shell to an alpine Container
$ docker run -it alpine /bin/sh
# Display All Docker Processes
$ docker ps -a
$ docker ps
$ docker images
$ docker run hello-world
# Echo “Hello, World!” as a Service
$ docker run alpine /bin/echo 'Hello, World!'
# Time the Execution of the Echo Service
$ time docker run alpine /bin/echo 'Hello World!'
# Time the Execution of echo Natively
$ time echo 'Hello World!'
# Time a Hard Sleep Natively
$ time sleep 2
# Time a Hard Sleep as a Service
$ time docker run alpine /bin/sleep 2
# Listing 4-18. Display Currently Running Containers/Processes
$ docker run -d alpine /bin/sh -c "while true; do echo hello world; sleep 1; done"
# Display Currently Running Containers/Processes
$ docker ps
# Show Logs for a Detached Container
$ docker logs upbeat_easley
# Stop a Detached Container
$ docker stop upbeat_easley
While an application may run more than one process at a time, these processes should be stateless.
one process per container
# Prepare for Local Development
$ mkdir dockerfiles && cd dockerfiles
$ git init
$ touch README.md
$ git add README.md
$ git commit -m 'init'
On GitHub, create a repo called Dockerfiles.
$ git remote add origin git@github.com:<username>/dockerfiles.git
$ git push -u origin master
#Display docker build help
$ docker build
# Comment
INSTRUCTION arguments
GNU Scientific Library (GSL)
Create the gsl Source Directory
# Create a Directory for the gsl Image Containing an Empty Dockerfile
$ mkdir gsl
$ touch gsl/Dockerfile
# Run a Docker Build
$ docker build -t joshuacook/gsl gsl
Define the gsl Image
$ vim Dockerfile
FROM gcc
LABEL maintainer=@joshuacook
RUN apt-get update && \
apt-get install -y \
gsl-bin \
libgsl0-dbg \
libgsl0-dev \
libgsl0ldbl
Build the gsl Image
$ docker build -t joshuacook/gsl gsl
Step | Description |
---|---|
Step 1 : FROM gcc | A valid Dockerfile must always begin with a FROM instruction. |
Step 2 : LABEL maintainer @joshuacook | The second layer uses the LABEL instruction to define metadata associated with your image. Each LABEL is a key-value pair. |
Step 3 : RUN apt-get update && apt-get install -y | The final layer of the image uses the RUN instruction, in this case to install the libraries necessary for using the GNU Scientific Library. |
$ docker inspect joshuacook/gsl
# Commit Changes and Push to GitHub
$ git add gsl/Dockerfile
$ git commit -m 'GSL IMAGE - initial build'
$ git push
Add an Additional Dependency Layer to joshuacook/gsl
RUN apt-get update && \
apt-get install -y gdb
# Rerun the joshuacook/gsl Image Build
$ docker build -t joshuacook/gsl gsl
# Rerun the Identical Build Once More
$ docker build -t joshuacook/gsl gsl
Create the miniconda3 Source Directory
# Create a Directory for the miniconda3 Image Containing an Empty Dockerfile
$ mkdir miniconda3
$ touch miniconda3/Dockerfile
$ tree
Begin the Image with FROM, ARG, and MAINTAINER
miniconda3/Dockerfile
FROM debian
# Build the miniconda3 Image
$ docker build -t miniconda3 miniconda3
# Show Cached Images
$ docker images
Commit Changes to the Local Repository
$ git add Dockerfile
$ git commit -m 'MINICONDA3 IMAGE. Added FROM instruction.'
miniconda3/Dockerfile
FROM debian
LABEL maintainer=@joshuacook
ARG DEBIAN_FRONTEND=noninteractive
# An ARG Passed at Build Time
$ DEBIAN_FRONTEND=noninteractive docker build -t some_image .
Idempotently Run the Build
# Run the Build
$ docker build -t miniconda3 miniconda3
Commit Changes to the Local Repository
# Commit Changes
$ git add Dockerfile
$ git commit -m 'MINICONDA3 IMAGE. Added maintainer LABEL and ARG instruction'
Provision the miniconda3 Image
The RUN Instruction
RUN <command>
A RUN Instruction
RUN /bin/bash -c 'source $HOME/.bashrc ; echo $HOME'
Another RUN Instruction
RUN /bin/bash -c 'source $HOME/.bashrc ;\
echo $HOME'
miniconda3/Dockerfile
RUN apt-get update --fix-missing && \
apt-get install -y \
wget bzip2 ca-certificates \
libglib2.0-0 libxext6 libsm6 libxrender1
Run the Build
# Run the Build
$ docker build -t miniconda3 miniconda3
# Idempotently Run the Build
$ docker build -t miniconda3 miniconda3
# Display Images in the Local Image Cache
$ docker images
Commit Changes to the Local Repository
# Commit Changes
$ git add Dockerfile
$ git commit -m 'MINICONDA3 IMAGE. OS provision statement.'
Install Miniconda
miniconda3/Dockerfile
RUN echo 'export PATH=/opt/conda/bin:$PATH' > /etc/profile.d/conda.sh && \
wget --quiet \
https://repo.continuum.io/miniconda/Miniconda3-4.3.11-Linux-x86_64.sh -O
~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh
Run the Build
# Run the Build
$ docker build -t miniconda3 miniconda3
Commit the Changes to the Local Repository
# Commit Changes
$ git add Dockerfile
$ git commit -m 'MINICONDA3 IMAGE. Install miniconda3.'
miniconda3/Dockerfile
RUN apt-get install -y curl grep sed dpkg && \
TINI_VERSION=`curl https://github.com/krallin/tini/releases/latest |
grep -o "/v.*\"" | sed 's:^..\(.*\).$:\1:'` && \
curl -L "https://github.com/krallin/tini/releases/download/v${TINI_
VERSION}/tini_${TINI_VERSION}.deb" > tini.deb && \
dpkg -i tini.deb && \
rm tini.deb && \
apt-get clean
Run the Build
# Run the Build
$ docker build -t miniconda3 miniconda3
Commit the Changes to the Local Repository
# Commit Changes
$ git add Dockerfile
$ git commit -m 'MINICONDA3 IMAGE. Install tini.'
Configure the Environment Variable with ENV
miniconda3/Dockerfile
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH
miniconda3/Dockerfile
ENTRYPOINT [ "/usr/bin/tini", "--" ]
Run the Build
# Run the Build
List of posts followed by this article
Reference
-
Joshua Cook, Docker for Data Science, Building Scalable and Extensible Data Infrastructure Around the Jupyter Notebook Server