Skip to content

Instantly share code, notes, and snippets.

@HikariJadeEmpire
Last active December 17, 2023 08:59
Show Gist options
  • Save HikariJadeEmpire/450eb3b5ad20b2df04625a33baf36490 to your computer and use it in GitHub Desktop.
Save HikariJadeEmpire/450eb3b5ad20b2df04625a33baf36490 to your computer and use it in GitHub Desktop.
# source : https://www.youtube.com/watch?v=pg19Z8LL06w&t=16s
# Docker images = Your Application include environment config , variables , directories
# Docker container = Actually starts the app
# One image can run multiple containers
########################################################################
############################### COMMAND ################################
########################################################################
#### LISTS ####
$ docker images
# List all Docker images
$ docker ps
# Lists running container (Only running)
$ docker ps -a | --all
# Lists running container (Stopped and running)
# '|' means you can only use -a or --all
$ docker system prune -a
# for removing and cleaning up Docker images.
#### Start & Stop ####
$ docker start { CONTAINER_ID or name }
$ docker stop { CONTAINER_ID or name }
$ docker pull { name }:{ version(tags) }
# Pull an image from registry , Example : https://hub.docker.com/_/nginx/tags
$ docker run { name }:{ version(tags) }
# Creates a container from given image and starts it
$ docker run -d | --detach { name }:{ version(tags) }
# Runs container in background and Prints the container ID
$ docker run --name { name } -d { name }:{ version(tags) }
# Runs container in background and Prints the container ID with assigning it's name
$ docker run -p | --publish { HOST_PORT or any localhost }:{ CONTAINER_PORT } { name }:{ version(tags) }
# Publish container to the port
Example : docker run --name { name } -d -p { HOST_PORT }:{ CONTAINER_PORT } { name }:{ version(tags) }
#### LOGS ####
$ docker logs { CONTAINER_ID }
# View logs from service running inside the container. (Which are present at the time of execution)
#### More ####
https://docs.docker.com/reference/
###################################################################################
################################ CREATE Dockerfile ################################
#### we create docker file when we have our own app which is not 'pull' method ####
###################################################################################
###################################################################################
FROM { name }:{ version(tags) }
# Build image from the specified image
RUN { command }
# Will execute any command in a shell inside the container environment
COPY { file or directory } { container path }
# Copies files or directories from <src> and adds them to the filesystem of the container at the path <dest>
# While 'RUN' is execute in the container, 'COPY' is execute on the host
Example :
COPY myfile.json /app/
COPY <any diretories> /app/
WORKDIR { path }
# Sets the working directory for all following commands ( like $ cd <dir> )
CMD
# The instruction that is to be executed when a Docker container starts
# There can only be one 'CMD' instruction in a Dockerfile
########### Dockerfile Example & how to correct syntax order ###########
FROM { name }:{ version(tags) }
COPY { file or directory } { container path }
WORKDIR { path }
RUN { command }
CMD [ "{ app name from 'FROM' }" , "{ file from 'COPY' }" ]
**Dockerfile is the definition to build Image**
########################################################################
# To build Image
$ docker build -t | --tag { name }:{ tag } { location of Dockerfile }
########################################################################
################################ VOLUME ################################
########################################################################
a volume is a persistent storage location that exists outside of the container.
Volumes are useful for storing data that needs to persist even if the container is stopped or removed.
In a Dockerfile, the VOLUME instruction is used to specify a mount point for a volume within the container.
########################################################################
############################# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment