Reputation: 4460
I propably have missed something. So, I have installed docker on the production server and I have have a running application locally. It starts and runs on docker-compose.
So I feel like I am almost ready for deployment.
No I'd like to build a docker image and deploy it to the to the production server.
But when I try to build the image from the docker compose files like this
docker-compose -f docker-compose.base.yml -f docker-compose.production.yml build myapp
I keep getting ERROR: No such service: app
I haven't found any documentation the docker site, where the image build procedure from multiple dock-compose files is described. Maybe it's there, but then I have missed it.
My other Problem i.e. question is: where would I place the image tar(.gz) files on the target server.
Can I specify the target location for the images in either the /etc/docker/daemon.json or some other configuration file?
I simply don't know where to dump the image file on the production server.
Again, maybe there is some documentation somewhere on the docker web site. But if so, then I've missed that too.
Addendum source files
I was asked to add my docker-compose files to provide a running example. So, here's the entire code for development and production environments.
For the sake of simplicity, I've kept this example quite basic:
Dockerfile.base
# joint settings for development, production and staging
FROM mariadb:10.3
Dockerfile.production
# syntax = edrevo/dockerfile-plus
INCLUDE+ Dockerfile.base
# add more production specific settings when needed
Dockerfile.development
# syntax = edrevo/dockerfile-plus
INCLUDE+ Dockerfile.base
# add more production specific settings when needed
docker-compose.base.yml
version: "3.8"
services:
mariadb:
container_name: my_mariadb
build:
context: .
volumes:
- ./../../databases/mysql-my:/var/lib/mysql
- ~/.ssh:/root/.ssh
logging:
driver: local
ports:
- "3306:3306"
restart: on-failure
networks:
- backend
networks:
backend:
driver: $DOCKER_NETWORKS_DRIVER
docker-compose.production.yml
services:
mariadb:
build:
dockerfile: Dockerfile.production
environment:
PRODUCTION: "true"
DEBUG: "true"
MYSQL_ROOT_PASSWORD: $DBPASSWORD_PRODUCTION
MYSQL_DATABASE: $DBNAME_PRODUCTION
MYSQL_USER: $DBUSER_PRODUCTION
MYSQL_PASSWORD: $DBPASSWORD_PRODUCTION
docker-compose.development.yml
services:
mariadb:
build:
dockerfile: Dockerfile.development
environment:
DEVELOPMENT: "true"
INFO: "true"
MYSQL_ROOT_PASSWORD: $DBPASSWORD_DEVELOPMENT
MYSQL_DATABASE: $DBNAME_DEVELOPMENT
MYSQL_USER: $DBUSER_DEVELOPMENT
MYSQL_PASSWORD: $DBPASSWORD_DEVELOPMENT
This starts up properly on my development machine when running:
docker-compose -f docker-compose.base.yml \
-f docker-compose.development.yml \
up
But how do I get from here to to there i.e. how can I turn this into self contained image which I can upload to my docker production host?
And where do I put it on the server so the docker production server can find it?
I think I should be able to upload and run the built image without running compose again on the production host, or shouldn't I?
For the time being, the question remains:
Why does this build command
docker-compose -f docker-compose.base.yml \
-f docker-compose.production.yml \
build app
return ERROR: No such service: app?
Upvotes: 1
Views: 4182
Reputation: 9063
I see two separate issues in your question:
To "deploy" / start a new image on a production server it needs to be downloaded with docker pull
, from a registry where it was uploaded with docker push
- i.e. you need a registry that is reachable from the production server and your build environment.
If you do not want to use a registry (public or private one) you can use docker export
to export an image as a tar-ball which you can manually upload to the production server and make it available with docker import
.
Check docker image ls
to see if a specific image is available on your host.
But in your case I think it would be the easiest to just upload your docker-compose.yml
and related files to the production server and directly build the images there.
docker-compose -f docker-compose.base.yml \
-f docker-compose.production.yml \
build app
Because there is no service app
! At least in the files you provided in your question there is only a mariadb
service defined and no app
service.
But starting / building the services should be the same on your local dev host and the production server.
Upvotes: 2