-
-
Save monirshimul/30dc0209435057e3e1c07577060b8f70 to your computer and use it in GitHub Desktop.
Docker cheat sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Running a container (run command will downlaod a and install a image) | |
| docker run hello-world | |
| // Running a command inside a container | |
| docker run busybox echo hi there | |
| docker run busybox ls | |
| // Listing all container running | |
| docker ps | |
| // Listing all the cointainer runned till now | |
| docker ps --all | |
| // container life cycle | |
| docker run = docker create + docker start | |
| docker create hello-world | |
| // docker removing all the stopped container | |
| docker system prune | |
| // Logging output of the container in the terminal | |
| docker logs <container_id> | |
| // stopping a running container | |
| // soft stop | |
| docker stop <container_id> | |
| // hard stop | |
| docker kill <container_id> | |
| // running command into running container | |
| docker exec <container_id> <command> | |
| ex : docker exec -it <container_id> echo hello world | |
| // running a shell inside a container | |
| docker exec -it <container_id> sh | |
| docker run -it <image_name> sh | |
| // docker remove images | |
| docker rmi <image id> | |
| docker rmi $(docker images -q) | |
| // docker remove container | |
| docker rm <container id> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. Making a Dockerfile | |
| //Dockerfile | |
| FROM alpine | |
| RUN apk add --update redis | |
| CMD ["redis-server"] | |
| 2. build the image | |
| docker build . | |
| or | |
| docker build -t <reponame>/<image_name>:<version> . | |
| 3. Take the image id or name and run | |
| docker run <image_id> | |
| or | |
| docker run <reponame>/<image_name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. Create a node app | |
| 2. Create Dockerfile | |
| //Dockerfile | |
| FROM node:alpine | |
| WORKDIR /usr/app | |
| COPY ./package.json ./ | |
| RUN npm install | |
| COPY ./ ./ | |
| CMD ["npm", "start"] | |
| 3. Build the image | |
| docker build -t ovi/node . | |
| 4. Run the Image | |
| docker run -p 8080:3000 ovi/node | |
| 5. Enjoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| work: Creating a node app with redis database using two separate container | |
| 1. Create a Dockerfile for node app (check-3) | |
| 2. write a docker-compose.yml file | |
| // docker-compose.yml | |
| version: '3' | |
| services: | |
| redis-server: | |
| image: 'redis' | |
| node-app: | |
| build: . | |
| ports: | |
| - "8080:3000" | |
| restart: 'no' | |
| 3. after writing docker-compose issue the command | |
| docker-compose up --build | |
| or | |
| docker-compose up | |
| 4. for stopping all the container created by docker-compose | |
| docker-compose down | |
| 5. for showing all the container started by docker-compose | |
| docker-compose ps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment