Docker
Docker
FROM node:alpine
COPY . /app
WORKDIR /app
CMD node node.js
exec -it -u john <id of container> bash # it will execute in john session
Lecture 30:
Install node
npm install # it will check the dependencies from package.json and download them
npm start
Lecture 31:
Docker File:
1. FROM (for specifying the base image)
2. WORKDIR (for specifying working dir)
3. COPY (for copying files and dir)
4. ADD (same as above)
5. RUN (for executing operating sys commands)
6. ENV (for setting environment variables)
7. EXPOSE (for telling docker container is running on specific port)
8. USER (user for running process)
9. CMD (for specifying command to be executed when we start a container)
10. ENTRYPOINT (same as above)
ADD automatically uncompress the zip file and it is also used to get file from url
.dockerignore (this file includes files and directories that we don't want in image)
Direct cmd instructions like CMD npm start will create a shell and then execute also it is bit
slower to overcome it we use CMD [“npm”, “start”]
CMD instruction is flexible and everyone can easily modify it (as it is default command so
anyone can change it by writing command after run instruction of docker) that`s why
ENTRYPOINT is used which array of string and to overwrite it --entrypoint used in run
instruction of docker image.
docker images prune #it will delete all the dangling images
docker container prune # same as above
You can set the tag of image by adding : and tag name followed by the name of image in build
command
Docker image tag <image name>:<new tag> <image name>:<previous tag> #it will add image
with new tag
Docker image tag <image id> <image name>:latest # it will add latest tag to given image
docker login
docker push <online repository>/<image name>:<tag> #automatically specify it as latest
(lecture 44)
docker image save -o reachapp.tar reactapp:<version>
Docker image load -i reactapp.tar
(lecture 46)
Docker run -d reactapp # run react app in detach mode
docker run -d --name <name of your choice> reactapp # without name option docker assigns a
random name to it
Lecture 47:
docker logs <container id>
Lecture 48:
docker -d -p 80:3000 --name c1 reactapp #port 80 is mapped over 3000 of container
Lecture 49:
docker exec c1 [linux commands ]
Lecture 50:
Docker start c1
docker stop c1
Lecture 51:
docker ps -a | grep c1 # only work in linux
Lecture 53:
Volume: space you can create outside container. It can be in cloud or pc.
docker volume create app-data
docker exec -d -p 4000:3000 -v app-data:/app/data reactapp #-v is used for volume
Lecture 54:
docker cp secret.txt <container id>:<destination>
docker cp <container id>:<source> <destination>