Docker is a tool to run applications in an isolated environment. It provides the same advantages as running the application on a virtual machine but its way more lightweight, fast and offers many more advantages.
2. Sandbox projects
3. Eliminates the configuration and setup phase of virtual box
Adventages:
1. Same environment2. Sandbox projects
3. Eliminates the configuration and setup phase of virtual box
Demo
There is a tutorial here. Go through the Docker for Beginners workshop and you will have a very good understanding of using docker.
I am going to list few of the commands as a reference in this blog.
First complete these steps:
Lets say you have a container running(say ubuntu). Now you want to connect to the container and run some shell scripts from your host machine. You can run hit this command to connect to the running container and test if the scripts work or not.
Run mongodb in docker:
Run another container and line the previous container to it (mongo)
for example:
MONGO_PORT_27017_TCP_ADDR = 127.0.0.10
which can be accessed from a nodejs app running in peda by
process.env.MONGO_PORT_27017_TCP_ADDR
If the container started successfully, it could be attached from the command line of host using the following command.
To push the image to the hub
To see logs of a server (for debugging)
Simple right
I am going to list few of the commands as a reference in this blog.
First complete these steps:
- Install Docker in your machine
- Start the docker service
- Run a standard container (ie Hello world, or alpine)
Note: If you are linux user, add your user to sudo group to avoid typing sudo infront of every docker commandBasic commands
- Check Docker info
docker info
- Check docker images in your machine
docker images
- check docker processes
docker ps
docker ps -a
stop docker process
docker stop <container-id or container-name>
- Remove docker process
docker rm <container-id or container-name>
- Remove docker image
docker rmi <container-id or container-name>
- Run docker build to create an image
docker build -t USERNAME/IMG_TAG_NAME .
- Run image
docker run -p HOST_PORT:GUEST_PORT -v HOST_PATH:GUEST_PATH IMAGE_NAME .
Lets say you have a container running(say ubuntu). Now you want to connect to the container and run some shell scripts from your host machine. You can run hit this command to connect to the running container and test if the scripts work or not.
docker exec -it <container name or id> sh
Run mongodb in docker:
docker run --name mongo -p 27017:27017 -v ~/mongodb/data/:/data/db -d mongo
Run another container and line the previous container to it (mongo)
sudo docker run -itd -e NODE_ENV=production -e PEDA_HOST=peda.app.rajanu.com.np -e PEDA_PORT=3000 --link mongo --name=peda -p 3000:3000 rajanpupa/peda
The above command links the mongo container to the peda container and it will create some environment variables in the peda containers which can be used to connect to mongo container from peda container.for example:
MONGO_PORT_27017_TCP_ADDR = 127.0.0.10
which can be accessed from a nodejs app running in peda by
process.env.MONGO_PORT_27017_TCP_ADDR
If the container started successfully, it could be attached from the command line of host using the following command.
docker attach peda
To push the image to the hub
docker push rajanpupa/peda
before that, you need to have a docker hub account and you need to be logged in.docker login
To see logs of a server (for debugging)
docker logs <id>
Simple right