An open API service indexing awesome lists of open source software.

https://github.com/nikhilbadyaldevelops/learn-docker

What I know about Docker.
https://github.com/nikhilbadyaldevelops/learn-docker

docker docker-compose docker-image dockerfile

Last synced: about 2 months ago
JSON representation

What I know about Docker.

Awesome Lists containing this project

README

          

# Docker Commands

## Conainers

1. `docker --help` - To get help for commands.
1. `docker --help` - To get help for a particular command.
1. `docker ps -a` - lists all running ports. `-a` shows all containers without that it shows only running.
1. `docker stop --env/-e --env-file --rm -p --name -it -d -v ` - create container from image and run. if not available then download from docker hub. `-it` flags tells us to expose interactive terminal from container to our local machine. By default, it runs in attach mode.`-d` to run the container in detach mode.`--rm` flag tells to remove the container when it stops and anonymous volumes are also removed.`--name` to give custom name to the container.`-p` flags is to `publish`, under which port on our local machine the docker port should be accessible. `p1` is the local port and `p2` is container port.`-v` to add volumes.I can add `-v` two times to add bind mount.`--env` to set envioronment variables.
1. `docker build -t --build-args ` - Build an image from Dockerfile.`-t` to give custom tag to the
image. `` specifies the format of the tag.
1. `docker start -a -i ` - To start an existing container. By default, it starts in detach
mode.`-a` to start container in attach mode.`-i` for interactive shell.
1. `docker logs -f ` - To print the past logs in console.`-f` to tell docker that we want to follow
the future logs.(Kind of attach state)
1. `docker attach ` - Attach to a running container.
1. `docker rm ` - Remove container. Cannot remove running container.Can write multiple names separated
by space.
1. `docker container prune` - delete a stopped containers.
1. `docker images` - to list all images.
1. `docker rmi ` - to remove **`images`**. Only images which are not used.Mention tag if exist.
1. `docker image prune -a inspect` - `prune` remove all images.`inspect` used to inspect the image.`-a` tag to prune
images incl. tagged images.
1. `docker cp ` - to copy in/out to/from the container.`dest` will be created if it doesn't
exist.
1. `docker push :tagname` - It pushed the image to the host mentioned.
1. `docker pull ` - To rename a image.
1. `docker login` - To loign to docker hub
1. `docker logout` - to logout from docker hub.
1. `host.docker.internal`- to get access to local host
1. `docker exec `- to run command inside container.

## Volumes(Anonymous Volumes, Named Volumes, Bind Mounts)

1. `docker volume rm prune ls inspect create ` - `create` to create volume manually.`ls` to list all volumes.`inspect` to see details of a volume.`prune` to remove all unused **local** volumes.`rm` remove volume by name.
1. -v "%cd%:/app" in windows ( For Bind mounds)
1. -v ${pwd}:app in mac/linux
1. `docker run -v /app/data` - Anonymous Voumes.Survives shutdown/stopping of containers but not removal. Can't be shared by container. Created by `--v` flag or by writting docker file.
1. `docker run -v data:/app/data` - Named Volumes. Created by `--v` flages. In general and not linked to particular container. also survive removals. Can be shared across containers.
1. `docker run -v /path/to/code:/app/code` - Bind Mount. Not tied to particular container. Can be shared across containers. survives restart and removal.`ro` can be added to tell docker that its a read only volume.

## Network

1. `docker network create` - `create` to create a network

## Docker Compose

`exec`
`run`
`up`
`down` # environment: # - MONGO_INITDB_ROOT_PASSWORD: nikhil # - MONGO_INITDB_ROOT_USERNAME: nikhil # build: # context: ./backend # dockerfile: Dockerfile