Skip to content

Instantly share code, notes, and snippets.

@monirshimul
Forked from ovichowdhury/1. docker basic.txt
Created January 23, 2019 08:18
Show Gist options
  • Select an option

  • Save monirshimul/30dc0209435057e3e1c07577060b8f70 to your computer and use it in GitHub Desktop.

Select an option

Save monirshimul/30dc0209435057e3e1c07577060b8f70 to your computer and use it in GitHub Desktop.
Docker cheat sheet
// 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>
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>
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
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