I am just getting started with docker and I am trying to figure out how to deploy our webapplication. We got:
My first approach was to put it all inside one ubuntu-container and just deploy that. This lead into an awefully long dockerfile so I thought that cannot be the right way and I googled best practices and came to the point that each container should have only one concern.
Does that mean that I should use one container for each of the above mentioned processes and link them, which would result in 4 running containers (the database one having a volume)?
The advantages I see right now are:
The only two disadvantages I can think of are
It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.
Two options would be: Create a docker bridge network manually. Here are the docs for that. You'd just want to define a network with docker network create , add that network in your docker-compose, and make sure you put your frontend container in the same network when you docker run it by using the --network option.
Docker is a great tool that helps developers build, deploy, and run applications more efficiently in a standardized way. For frontend applications, we only need the Docker image for local development, because we deploy it to a static hosting provider.
You can use 4 different containers! With Docker you generally want to try to keep each container relatively simple but that doesn't mean you have to separate every component into different containers e.g. your web app from your server API (I have found it is useful to combine these in the same container becuase it makes communication easier) But it would be good practice to have your Database in a separate container. Docker has a tool called Docker Compose for launching container apps:
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you create and start all the services from your configuration. - Overview of Docker Compose
In order to use this tool you will:
Create a project directory with folders for each separate container.
Define your apps environment by creating a Dockerfile
for each of your containers (Web App / Server API) (Database) in there sub folder.
Dockerfile for Server API( and Web App (angular):
# Create image based on the official Node 6 image from dockerhub
FROM node:6
# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app/
# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app
# Get all the code needed to run the app
COPY . /usr/src/app
# Move into AngularApp directory
WORKDIR /usr/src/app/public
# Install dependencies for AngularApp
RUN npm install
# Changed to updated angular dependency
RUN ./node_modules/@angular/cli/bin/ng build
# Move into server directory
WORKDIR /usr/src/app/server
# Install dependencies for server
RUN npm install
# Return to top level directory of project
WORKDIR /usr/src/app
# Add API environment variables
ENV USERNAME="username"
ENV PASSWORD="password"
# Expose the port the app runs in
EXPOSE 4200
EXPOSE 80
WORKDIR /usr/src/app
docker-compose.yml
file. This file will define the services in your app so that they can be run together in an isolated environment. Compose file version 3 reference
A docker compose file follows this structure:
version: '3'
services:
web:
build: <directory with Dockerfile for service>
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
links:
- redis
database:
image: mongo
volumes:
logvolume01: {}
docker-compose up
and Compose will start to run you entire app!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With