Last active
September 19, 2018 17:03
-
-
Save MahbbRah/2bb6092c8c741580f9770e99d39fae07 to your computer and use it in GitHub Desktop.
Notes on using Docker [Step by Step]
This file contains 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
#Docker Installation: | |
First, add the GPG key for the official Docker repository to the system: | |
`curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -` | |
`sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"` | |
`sudo apt-get update` | |
Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo: | |
`apt-cache policy docker-ce` | |
Finally, install Docker: | |
`sudo apt-get install -y docker-ce` | |
After installation to check the status run: | |
`service docker status` | |
Congratulations, You've completed installing docker on your machine. | |
Now it's time to install images as needed | |
Create a file called `Dockerfile` in your project directory | |
Then add following lines on that file. | |
`` | |
FROM node:9.2 #here the image that you want to go with | |
# Create app Directory | |
RUN mkdir -p /usr/src/app | |
WORKDIR /usr/src/app | |
# Install app dependencies | |
COPY package.json /usr/src/app | |
Run cd /usr/src/app | |
Run npm install | |
Run node --version | |
# Bundle app source | |
COPY . /usr/src/app | |
EXPOSE 8585 | |
CMD ["npm", "start"] | |
`` | |
Now simple hit this command to build your project: | |
`sudo docker build -t CONTAINER_NAME .` | |
After the build process now hit this to run: | |
`sudo docker run -it -d -p NEW_PORT:EXPOSED_PORT --name THE_NAME_YOU_WANT CONTAINER_NAME_THAT_YOU_WANT_RUN_WITH` | |
To check running containers: | |
`sudo docker ps -a` | |
to stop process docker kill PROCESS_NAME | |
to delete a process docker rm PROCESS_NAME | |
to remove a container rmi CONTAINER_NAME | |
to update automatically without rebuilding everytime run your app like this way | |
sudo docker run -it -p 82:8585 -v /home/rakin/dockerg/:/usr/src/app my-kutus | |
#to open bash of a container inside docker | |
docker exec -it CONTAINER_NAME bash | |
#running docker containers in background | |
docker-compose up -d | |
#to stop all docker containers (running) | |
`docker stop $(docker ps -aq)` | |
#to build from source in local | |
`docker-compose build` [Optional flag `--no-cache`] | |
#building docker tag from current source | |
docker build -t dockermahbubrahman/mail-for-good:stable . | |
#pushing this as image to docker hub | |
docker push dockermahbubrahman/freecodecamp/mail-for-good:newVersionMahbub | |
for more visit: https://medium.freecodecamp.org/docker-easy-as-build-run-done-e174cc452599 | |
for more visit: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04#step-2-%E2%80%94-executing-the-docker-command-without-sudo-(optional) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment