Skip to content

Instantly share code, notes, and snippets.

@jcunanan05
Last active September 10, 2019 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcunanan05/aa118805321133b378f2b681eba8b590 to your computer and use it in GitHub Desktop.
Save jcunanan05/aa118805321133b378f2b681eba8b590 to your computer and use it in GitHub Desktop.
Docker commands
# when running folders with space
mypwd=$(pwd); docker run -p 8080:3000 -v ${mypwd}:/var/www -w "/var/www" node npm start
# folders without space
docker run -p 8080:300 -v $(pwd):/var/www -w "/var/www" node npm start
# interactive mode with bash
docker run -it -p 8080:3000 -v $(pwd):/var/www -w "/var/www" node /bin/bash
# building docker images
docker build -f Dockerfile -t jcunanan05/mycustomimage mydir
# daemon mode
docker run -d -p 8080:3000 jcunanan05/sample-node
# publishing custom docker images
docker push jcunanan05/sample-node
# stop all running containers
docker stop $(docker ps -a -q)
# execute a command inside a container
docker exec my-node-app node dbSeeder.js
#interactive mode
docker exec -it container_id /bin/bash
# create a bridge network
docker network create --driver bridge my_isolated_network
# run new container and add to an isolated network
docker run -d --net=my_isolated_network --name my-mongo-app mongo
# run new container and add to isolated network to an image
docker run -d --net=my_isolated_network --name my-node-app -p 3000:3000 jcunanan05/sample-node-mongo
# Docker COMPOSE
# build image
docker-compose build
# create a production container
docker-compose up
# start the container
docker-compose start
# run the dev environment, remove container after, use the ports
docker-compose run --rm --service-ports my_container_name
# pruning commands
# list GBs consumed by docker
docker system df
# prune all
docker system prune --volumes -a
@jcunanan05
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment