Prerequisites
Before undertaking the deployment steps, ensure that you have the necessary infrastructure set up. This includes:
- A container orchestration platform (like Kubernetes or Docker Swarm)
- Proper access controls and network settings
- A Docker registry for storing and retrieving images
Step 1: Build the Docker Images
The first step in the deployment process involves building the Docker images for your services. With the provided Dockerfile
, you can build the images using the Docker CLI.
Run the following command to build the images:
docker build -t your_image_name:latest .
During the build process, ensure that you are inside your project directory where the Dockerfile
is located. This command will build the images according to the specifications set in the Dockerfile.
Step 2: Write the Docker Compose Configuration
In this deployment scenario, we use docker-compose.yml
to define and run multi-container Docker applications. Here’s a brief overview of the configuration used:
version: "2"
services:
server:
build:
context: .
dockerfile: server.Dockerfile
networks:
- mdb
- sig
ports:
- "8080"
- "4443:4443"
entrypoint: /usr/bin/env sh
command: -c "./migrations/migrate.sh && notary-server -config=fixtures/server-config.json"
depends_on:
- mysql
- signer
signer:
build:
context: .
dockerfile: signer.Dockerfile
networks:
mdb:
sig:
aliases:
- notarysigner
entrypoint: /usr/bin/env sh
command: -c "./migrations/migrate.sh && notary-signer -config=fixtures/signer-config.json"
depends_on:
- mysql
mysql:
networks:
- mdb
volumes:
- ./notarysql/mysql-initdb.d:/docker-entrypoint-initdb.d
- notary_data:/var/lib/mysql
image: mariadb:10.4
environment:
- TERM=dumb
- MYSQL_ALLOW_EMPTY_PASSWORD="true"
command: mysqld --innodb_file_per_table
volumes:
notary_data:
external: false
networks:
mdb:
external: false
sig:
external: false
In this configuration:
- services defines three containers:
server
,signer
, andmysql
. - Each service has a build context and a specified Dockerfile.
- Volumes are defined for MySQL data persistence.
Step 3: Deploy the Containers
To deploy your application stack defined in the docker-compose.yml
, you can use the following command:
docker-compose up -d
The -d
option runs the containers in detached mode, allowing them to run in the background. Docker Compose will handle the ordering based on the depends_on
configuration, ensuring that the MySQL container starts before the other services.
Step 4: Execute Database Migrations
After the containers are up, ensure that the database is initialized correctly by running the provided migrations. The entrypoint commands in the server
and signer
services already manage this:
./migrations/migrate.sh
Confirm that the migration script completes successfully for both services.
Step 5: Verify Deployment
To verify that your services are running properly, utilize the Docker CLI to check the status of your containers:
docker-compose ps
Additionally, you can access the logs for any service to diagnose issues:
docker-compose logs <service_name>
For example, to see logs of the server
service:
docker-compose logs server
Step 6: Configure Networking and Ports
Ensure that the ports specified in your docker-compose file are available and not blocked by firewalls or other services. Validate connectivity between services if they are running on different hosts or networks.
Step 7: Updating Services
For updating your services in production:
- Modify the codebase as necessary.
- Rebuild the Docker images:
docker-compose build
- Deploy updated containers without downtime:
docker-compose up -d
This will recreate the containers with the updated images.
Notes
Ensure that you are using the correct Go module to maintain build accuracy:
GO111MODULE=on go build github.com/docker/cli/docs/generate
Avoid utilizing the -mod=vendor
flag, as it is not applicable in this context.
Conclusion
Following the steps delineated will facilitate a reliable production deployment of your application using Docker. Each command and configuration should be tailored to your specific environment and requirements.
Source: Docker configuration and build details from docker-compose.yml
, Dockerfile
, and Makefile
.