Docker
Docker is an open-source centralized platform designed to create, deploy, and run applications. Docker uses container on the host's operating system to run applications. It allows applications to use the same Linux kernel as a system on the host computer, rather than creating a whole virtual operating system. Containers ensure that our application works in any environment like development, test, or production.
Basic Docker Commands
➜ ~ sudo docker info
➜ ~ sudo docker version
➜ ~ sudo docker search centos
download image
➜ ~ sudo docker pull <image>
➜ ~ sudo docker pull centos
which imaged on system
➜ ~ sudo docker images
All process run
➜ ~ sudo docker ps
All process Have Been Runned
➜ ~ sudo docker ps -a
For Remove Process with use container id
➜ ~ sudo docker rm < container id >
➜ ~ sudo docker rmi centos
Remove all process
➜ ~ sudo docker container prune
Remove image
➜ ~ sudo docker rmi < image name>
**Note : if you want to remove process after quit from image use --rm **
➜ ~ sudo docker run --rm -it busybox
Note : --it means interactive running
Runnig one command in one container
➜ ~ sudo docker exec < container id > touch "hi"
➜ ~ sudo docker run --rm redis
➜ ~ sudo docker run --rm p6379:6379 redis
Note: this means connect 6379 server port lto my 6379 my desktop port
Name a Docker Container
You can assign memorable names to your docker containers when you run them, using the --name flag as follows. The -d flag tells docker to run a container in detached mode, in the background and print the new container ID.
sudo docker run -d --name discourse_app local_discourse/app
From now
➜ ~ sudo docker restart discourse_app
➜ ~ sudo docker stop discourse_app
➜ ~ sudo docker start discourse_app
Rename a Docker Container
➜ ~ sudo docker rename discourse_app disc_app
Remove image with name
➜ ~ sudo docker run --remove redis
Download image
➜ ~ sudo docker pull <image_name>
start container
➜ ~ sudo docker start <container_id>
➜ ~ sudo docker start <Names>
stop container
➜ ~ sudo docker stop <container_id>
➜ ~ sudo docker stop <Names>
Port Config
➜ ~ sudo docker run -p 8080:80 nginx
Note :: if you want to ruuning in Background :
➜ ~ sudo docker run -d -p 8080:80 nginx
Run bash in ubuntu:18.04
➜ ~ sudo docker run --rm -it ubuntu:18.04 bash
-it : interactive --rm : remove container when exit
List of containers running now
➜ ~ sudo docker ps
List of containers running before but Not running now
➜ ~ sudo docker ps -a
List of images
➜ ~ sudo docker images ls
➜ ~ sudo dockger images
Remove image
➜ ~ sudo docker rmi <image_name>
➜ ~ sudo docker rm <image_id>
command Running
➜ ~ sudo docker exec -it <container_id> bash
➜ ~ sudo docker exec -it <container_name> bash
Example :
➜ ~ sudo docker exec -it 165489125 cat /etc/os-release
Connect Directories to Serve
➜ ~ docker run -d -p 8080:80 -v /home/koosha/Desktop/templates:/usr/share/nginx/html nginx
Note: Read Only Options
➜ ~ docker run -d -p 8080:80 -v /home/koosha/Desktop/templates:/usr/share/nginx/html:ro nginx
Save (Backup)
➜ ~ docker save -o /home/koosha/Desktop/nginx.tar nginx
Load Backup File
➜ ~ docker load -i /home/koosha/Desktop/nginx.tar
Create Name for running easly
➜ ~ docker run -d --name koosha_webserver -p 8080:80 nginx
Docker Compose
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.
version: "3" service: website: image: umage:latest container-name: website3 ports: - "8080:80" - "3360:3306"
➜ ~ sudo docker-compose up
Diff
Show Difference What Changing on Ubuntu
➜ ~ docker diff <container_id>
Commit
when you change image and You want to save your own image you should be commit
➜ ~ sudo docker commit -a "koosha yenageh" -m "New configs of Ubuntu" <container_id> myubuntu:V1.0
Note: you should give Tag and version to complete commit
Dockerfile
FROM ubuntu:18.04
LABEL maintainer="koosha yeganeh"
RUN apt update && apt install nginx -y && apt install mariadb-server && apt install vim -y && apt install wget && apt install git && echo "UTC" > /etc/timexone
RUN apt update && apt install python3 && apt install python3-pip
RUN apt update && pip3 install virtualenv && cd /home && mkdir koosha && cd /koosha && virtualenv venv && source venv\bin\activate && pip3 install flask && pip3 install flask-login && pip3 install flask-limiter && pip3 install pymysql \
Last updated