0% found this document useful (0 votes)
21 views

Docker

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Docker

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Docker File:

FROM node:alpine
COPY . /app
WORKDIR /app
CMD node node.js

CMD( to Build it):


Docker build -t <file name> <where it will find the dockerfile>

CMD (for list of docker images):


Docker image ls

CMD(to run docker container):


Docker run <file name>

CMD (to pull image to your machine):


Docker pull <image name>
Docker run <image name> #docker will download the image iff it is not in the machine and run.

Docker ps #list running processes


Docker ps -a #lists all the processes
Docker run -it ubuntu # it runs the ubuntu in interactive mode

Show Prompt( it runs the ubuntu commands)


docker start -i 2f7 #it starts the container. We can write only the part of id so that docker can
# distinguish it from other containers

exec -it -u john <id of container> bash # it will execute in john session

Container is an isolated environment for executing process

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

docker run -it react-app sh # sh for executing shell

.dockerignore (this file includes files and directories that we don't want in image)

RUN is a buildtime instruction and CMD is run time

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

docker image # it will return the all the functions

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>

You might also like