[Trick] Build a enviroment Node.js and MongoDB to develop with Docker

Testing and build in host:

Distributor ID: Debian
Description: Debian GNU/Linux 9.8 (stretch)
Release: 9.8
Codename: stretch

Oficial Docker for MongoDB:
https://hub.docker.com/_/mongo/

Sigue leyendo

Anuncios

Cheat sheet Docker

## Available commands
docker help 
docker --help

## Specific Docker Command
man docker-run

## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world
docker run ubuntu /bin/echo 'Hello Jorge'

## List Docker images
docker image ls
docker images

## find an image to download
docker search debian

## Download image
docker pull debian:stable

## Create a container
docker run -i -t IMAGE_ID /bin/bash

exit to end session in your guest and the container will be stop and kept in your Docker

## see what container are known to your Docker
docker ps -a

## re-enter in one container
docker start CONTAINER_ID
docker attach CONTAINER_ID

## Save the container as a new image
docker commit CONTAINER_ID debian:stable

You can specify a new image name or overwrite the existing image name.


## List Docker containers (running, all, all in quiet mode)
docker container ls (or docker ps)
docker container ls --all (or docker ps -a)
docker container ls -aq  (or docker ps -aq)

## Create a Docker image
docker build -t IMAGE_NAME PATH_DIRECTORY

## Execute Docker image
docker run hello-world
docker run IMAGE_NAME
docker run -p 4000:80 IMAGE_NAME

## Run in background
docker run -d -p 4000:80 IMAGE_NAME
docker run --name CONTAINER_NAME -d ubuntu /bin/bash -c "while true; do echo 'Hello Docker'; sleep 1; done"

## Logs and see background container
docker logs -f CONTAINER_NAME

## End of the background process
docker container stop CONTAINER_ID
docker stop CONTAINER_NAME

## Start container an background process
docker start CONTAINER_NAME

## Delete all containers
docker rm -f $(docker ps -aq) 
docker rm $(docker ps -a -q)

## Delete all images
-f: forced
docker rmi $(docker images -q)

## login in the Docker public registry
docker login

## Associating a local image with a repository on a registry
docker tag IMAGE_NAME username/repository:tag

## Upload your image to the repository
docker push username/repository:tag

## Pull and run the image from the remote repository
docker run -p 4000:80 username/repository:tag

## use volumes: local file on container? 
docker run -v /home/user/Project:/mnt/Project -i -t IMAGE_ID /bin/bash

## multiple terminals to launch several session connected to the same container
docker exec -it CONTAINER_ID /bin/bash

Example:
docker run -it container_name bash (starts a new container with bash promt)
docker exec -it container_name bash (joins already running container's bash prompt)

[Trick] How do Backup in PostreSQL

Postgres have the tool pg_dump the which is used for do backups.

$ pg_dump -i -F c -b -v -f backup_name.bk database_name

add -s, –schema-only: for dump only the schema, no data.

Create the database if no existing:

$ createdb --locale=en_US.UTF-8 --owner=postgres -W database_name

Restore backup:

$ pg_restore -i -d database_name -v backup_name.bk