0% found this document useful (0 votes)
5 views4 pages

Docker Notes

The document outlines deployment options for applications, including single host and cluster deployments using orchestration tools like Docker Swarm and Kubernetes. It details the process of setting up a Virtual Private Server (VPS) with providers such as Digital Ocean and AWS, as well as using Docker Machine to create production images and deploy applications. Additionally, it covers optimizing image sizes, managing production configurations, and addressing common deployment issues.

Uploaded by

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

Docker Notes

The document outlines deployment options for applications, including single host and cluster deployments using orchestration tools like Docker Swarm and Kubernetes. It details the process of setting up a Virtual Private Server (VPS) with providers such as Digital Ocean and AWS, as well as using Docker Machine to create production images and deploy applications. Additionally, it covers optimizing image sizes, managing production configurations, and addressing common deployment issues.

Uploaded by

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

Deployment

In this section :-
●​ Deployment options
●​ Getting a Virtual Private Server (VPS)
●​ Using Docker Machine
●​ Creating optimized production images
●​ Deploying the application

1.​ Deployment options -


a.​ Single host deployment
b.​ Cluster deployment-
i.​ We need orchestration tools :- docker swarm, kubernetes
2.​ VPS -
a.​ Digital Ocean
b.​ Google Cloud Platform (GCP)
c.​ Microsoft Azure
d.​ Amazon Web Services (AWS)
3.​ Install the docker machine using github
4.​ Provision a Host in Digital Ocean
>> docker-machine create `
>> --driver digitalocean `
>> --digitalocean-access-token
dop_v1_c01c60090b9336637d1cd70d9be83198e5be15ef1f0a597474e4d3502b48eb6a
`
>> --digitalocean-image "ubuntu-20-04-x64" `
>> --engine-install-url "https://releases.rancher.com/install-docker/19.03.9.sh" `
>> my-app

5.​ Connecting to the host with Secure Shell (SSH)


a.​ >> docker-machine ls << To view the droplet or server
b.​ >> docker-machine ssh my-app << Log in to the remote server using ssh
6.​ Defining the production configuration
a.​ We should first create a separate compose file for production environment
(docker-compose.prod.yml)
b.​ We normally remove the volumes of frontend and back end.
c.​ version: "3.8"
d.​
e.​ services:
f.​ frontend:
g.​ build: ./frontend
h.​ ports:
i.​ - 80:3000
j.​ restart: unless-stopped
k.​ backend:
l.​ build: ./backend
m.​ ports:
n.​ - 3001:3001
o.​ environment:
p.​ - DB_URL=mongodb://db/vidly
q.​ command: ./docker-entrypoint.sh
r.​ restart: unless-stopped
s.​ db:
t.​ image: mongo:4.0-xenial
u.​ ports:
v.​ - 27017:27017
w.​ volumes:
x.​ - vidly:/data/db
y.​ restart: unless-stopped
z.​
aa.​volumes:
bb.​ vidly:

7.​ Reducing the image size


a.​ Create new frontend docker (Dockerfile.prod) file as following -
i.​ # Step 1: Build stage
ii.​ FROM node:14.16.0-alpine3.13 AS build-stage
iii.​
iv.​ WORKDIR /app
v.​ COPY package*.json ./
vi.​
vii.​ # Install dependencies and fix Babel version
viii.​ RUN npm install
ix.​ RUN npm install @babel/[email protected]
x.​
xi.​ COPY . .
xii.​ RUN npm run build
xiii.​
xiv.​ # Step 2: Production stage
xv.​ FROM nginx:1.12-alpine
xvi.​ RUN addgroup app && adduser -S -G app app
xvii.​
xviii.​ # Copy the build files to the nginx html directory
xix.​ COPY --from=build-stage /app/build
/usr/share/nginx/html
xx.​
xxi.​ # Switch to the app user for better security
xxii.​ USER app
xxiii.​
xxiv.​ EXPOSE 80
xxv.​ ENTRYPOINT ["nginx", "-g", "daemon off;"]

Then also update the docker-compose production file.Then optimized


build version will create the container.

8.​ Deploying -
a.​ >> docker-compose -f docker-compose.prod.yml up -d << Simply deploy the app
b.​ >> docker-machine ls << check wether the app is online.
9.​ Dealing with issues
a.​ Remove the USER app from frontend dockerfile to use as the root user. Other
wise we will have permission issues.(But this way is not recommended)
b.​ Update Backend API calls in frontend by replacing localhost with actual hosted ip
address.
c.​ We need to get the command to activate the docker machine by using >>
docker-machine env my-app <<
d.​ In my case I got this from previous command and I should run this >> &
"C:\Users\asus\bin\docker-machine.exe" env my-app | Invoke-Expression <<
e.​ Then this docker client will send the any command to the target machine after
above.
f.​ After that we can run >> docker-compose up << to start the server.
10.​ Publishing Changes
a.​ >> image: compose-app_frontend:1 << We can version the app changes by
adding these commands under each service in docker-compose files.

--The End

You might also like