Skip to content

Instantly share code, notes, and snippets.

@kevin3747118
Last active June 19, 2017 07:29
Show Gist options
  • Save kevin3747118/dce4c1213c39d5ae2224e0c36360f6f2 to your computer and use it in GitHub Desktop.
Save kevin3747118/dce4c1213c39d5ae2224e0c36360f6f2 to your computer and use it in GitHub Desktop.

Docker Note

Install Docker on Ubuntu

Install from Ubuntu repo - older verion

$ sudo apt-get update 
$ sudo apt-get install -y docker.io

Install from Docker official - new version

$ sudo apt-get update
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu (lsb_release -cs) stable"
$ sudo apt-get update
$ apt-cache policy docker-ce

Check Docker status

$ service docker status

Docker Command

Search image from docker hub : Reference

$ docker search centos

Get image from docker hub : Reference

$ docker pull centos

List all docker images : Reference

$ docker images 

Run docker images : Reference

$ docker run -it centos /bin/bash
$ docker run -d --name service_name -p 8080:80 python3 manage.py runserver

Run a command in a running container : Reference

$ docker exec -it [container-id] /bin/bash

Start a container ran before : Reference

$ docker start [container-id]

Copy file to running container : Reference

$ docker cp file_name container_id:container_path

Commit modified container : Reference

$ docker commit -m 'commit reason' container_id your_name/container_name:tag

Share data with container -v [HOST_DIR]:[CONTAINER_DIR]

$ docker run -it -v [HOST_DIR]:[CONTAINER_DIR] bash

Delete image & container : Reference

  • Delete image :
$ docker rmi container_id
  • Delete container :
$ docker rm $(docker ps -a -q)

Leave & Kill container :

  • Leave container : Ctrl + p and Ctrl + q
  • Kill container : Ctrl + D or exit

Make Dockerfile

Dockerfile example : Reference

FROM ubuntu:16.04

RUN \
 apt-get update && \
 apt-get install -y gcc unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc vim python3 python3-pip && \
 pip3 install --upgrade pip && \
 pip3 install --no-binary pymssql pymssql
 
ADD Logistic_Parse /root/Logistic_Parse

RUN cd /root/Logistic_Parse && pip3 install -r requirements.txt

Build image from dockerfile : Reference

$ docker build -t your_name/image_name:tag .

Upload to docker hub : Reference

$ docker login
  • Push your dockerfile to docker hub
$ docker push your_name/image_name:tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment