Thursday, March 18, 2021

Docker Advance

 More detail in docker container command usage below:

1) Using environment to change the process argument 

$ docker run -e YOUR_ENV_FOO=YOUR_NEW_ARG --name YOUR_PROCESS_NAME YOUR_IMAGES


2) Building your own images with Dockerfile

$ docker build -t YOUR_IMAGES_TAG YOUR_FILE_PATH


3) Dockerfile example 

File_layout: Docker execute command and your process command

FROM - from any image public or local 

RUN - running a command from your image

COPY - copy a scipt to your image path

EXPOSE - expose a port for the web connection if your app is a web

ENTRYPOINT - the docker running process entry point , can be a modified environment entry point in running a image process

Ubuntu image Dockerfile below:

After docker run ubuntu image will calling bash command, so the docker run will execute ENTRYPOINT + CMD in Dockerfile

4) Running docker process in background detach mode

$ docker run -d YOUR_PROCESS


5) Linking your process with a database OR process related

$ docker run --link HOST_MAPED_NAME:DB_MAPPED_NAME -p HOST_MAPPED_PORT:CONTAINER_MAPPED_PORT wordpress


6) Create a docker compose yaml for running a batch process


7) Running a docker compose yaml under the yaml folder

$ docker-compose up 


8) Mapping a storage to link the container data to avoid the data lost with the process stopped

$ docker run -v HOST_DATA_PATH:CONTAINER_DATA_PATH 

Mapping back your data with the previous process

9) Listing current docker network

$ docker network ls


10) Inspect the detail of the network 

$ docker network inspect YOUR_CURRENT_NETWORK


11) Create a new subnet in the same network 

$ docker network create --driver YOUR_NETWORK --subnet YOUR_NEW_SUBNET --gateway YOUR_NEW_GATEWAY

Creating a new network , and run a process in a new network with the tag name




Docker Basic

 Summaries the docker basic command below:

1) Checking the version of docker

$ docker version


2) Listing the available images in your docker
$ docker images

3) Listing the current running process 
$ docker ps



4) Listing the all process included exited process in history
$ docker ps -a



5) Checking the process detail 
$ docker inspect your_process


6) Before remove the process, must stop the process 1st
$ docker stop your_process_id OR your process_name


7) After the process stopped , you can remove all the process
$ docker rm your_process_id OR your_process_name

8) Remove the unused images
$ docker rmi your_images_name

9) Pull the images from docker hub
$ docker pull docker_public_id_name

10) Running a container with tag 
$ docker run --name your_name_tag your_images_name