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
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
andCtrl + q
- Kill container :
Ctrl + D
orexit
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
- Create a docker hub account from official website
- Login in shell
$ docker login
- Push your dockerfile to docker hub
$ docker push your_name/image_name:tag