39
loading...
This website collects cookies to deliver better user experience
...is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.
The code used for this post is available on Github.
FROM golang:1.16.2-alpine3.13 AS builder
# ... commands are called here ...
FROM alpine:3.13 AS certificates
# ... more commands are called here ...
FROM scratch
# We refer to the previous stages, to copy the artifacts we created in previous stages.
COPY --from=certificates /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /build/rest-server ./bin/rest-server
builder
: it is used for building the binaries,certificates
: it is used for installing the required certificates, anddocker-compose
, this really depends on your personal preference, I like running the docker containers manually instead of depending on docker-compose, the reason for this is that, to date, there's no way to really depend on a service and wait until that one is completely initialized without adding a third-party program to handle that.docker-compose
we can re-run those containers after the ones that fail, using our To-Do Microservice docker-compose.yml
file for a concrete example, we do:docker-compose up
, this step will start all the required services with their corresponding containers, we expect the api service to fail because the postgres
service takes longer to start.docker-compose up api
only, then the api service will start successfully but we won't be able to interact with it because the database schema is not up to date, for that we need to run the database migrations.docker-compose run api migrate -path /api/migrations/ -database postgres://user:password@postgres:5432/dbname?sslmode=disable up
will complete the step of migrating the database to the new version and with that we finally have everything working correctly.