I am doing my first steps with docker compose and made a docker-compose.yml file which contains:
version: "3.8"
services:
web:
build: ./frontend
ports:
- "3000:3000"
api:
build: ./backend
ports:
- "3001:3001"
environment:
DB_URL: mongodb://db/slip
db:
image: mongo:4.0-xenial
ports:
- "27017:27017"
volumes:
- slip:/data/db
volumes:
slip:
However after running $ docker-compose build
This is my result images in docker:
REPOSITORY TAG IMAGE ID CREATED SIZE
slip_api latest 445199e1e418 43 seconds ago 184MB
slip_web latest c1168ad560b8 About a minute ago 299MB
node 14.16.0-alpine3.13 50bfd284aa0d 10 months ago 117MB
I am not sure why I don't see the mongo:4.0-xenial image, and also not sure why I see the node:14.16.0-alpine3.13 which is a base (FROM) in docker file of the slip_api and slip_web and not an image by itself that I built.
Using Ubuntu 20.04.3 LTS
Thanks for the help!
docker-compose build does literally that: it builds images. In order for an image to be built, the base image needs to present. That is the reason, why you are seeing the node image present.
You do not see the mongoDB image, because it is not built. Once you attempt to docker-compose up it will pull the latest version of mongo:4.0-xenial
Related
I have a docker-compose.yml file like so:
version: "3.8"
services:
app:
build:
context: .
dockerfile: Dockerfile
image: darajava/audio-diary
ports:
- 80:3001
volumes:
- .:/app
- "/app/node_modules"
depends_on:
- db
container_name: "soliloquy_express"
db:
image: mariadb:latest
restart: always
environment:
- MYSQL_DATABASE=soliloquy
- MYSQL_USER=soliloquy
- MYSQL_PASSWORD=password
- MYSQL_ROOT_PASSWORD=password
volumes:
- ../db_data:/var/lib/mysql
container_name: "soliloquy_db"
I'm planning to add an nginx service here too.
I use
docker-compose build
and
docker-compose push
to push to Docker Hub, which I can pull from (from my EC2 instance) using:
docker pull darajava/audio-diary:latest
However, when I run that image, it only runs the app service (I think).
using
docker-compose pull darajava/audio-diary:latest
does not work and leads to an error regarding a missing docker-compose.yml file.
So I have 2 questions:
Is there a way I can pull a whole docker-compose config, with app, db, and other services and pull and run it on my EC2 instance just by pulling from Docker Hub? or do I have the wrong use case for Docker Compose?
I'm using docker-compose to mount a volume on an image. I have the container running, but not able to pull the image in the browser.
Docker-compose has these below lines -
version: '2'
services:
jenkins:
image: image_name
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/gp_oes/project/jenkins_home:/var/jenkins_home
ports:
- 8080
I think you are trying to download the official image of ubuntu (https://hub.docker.com/_/jenkins) which was deprecated since last 2 years.
Please check with the community image of jenkins (https://hub.docker.com/r/jenkins/jenkins)
if it is not the case please provide error with command and image name also to give better understanding of the question.
I want to run an application using docker-compose on a Linux server that already has the images stored locally.
The application consists of two services. Running docker images on the server indicates that the images do in fact exist:
REPOSITORY TAG IMAGE ID CREATED SIZE
app_nginx latest b8362b71f3da About an hour ago 107MB
app_dash_alert_app latest 432f03c01dc6 About an hour ago 1.67GB
Here is my docker-compose.yml:
version: '3'
services:
dash_alert_app:
container_name: dash_alert_app
restart: always
build: ./dash_alert_app
ports:
- "8000:8000"
command: gunicorn -w 1 -b :8000 dash_histogram_daily_counts:server
nginx:
container_name: nginx
restart: always
build: ./nginx
ports:
- "80:80"
depends_on:
- dash_alert_app
When I run, docker-compose pull it seems to be able to see the images, and pulls them in:
$ sudo docker-compose pull
Pulling dash_alert_app ... done
Pulling nginx ... done
But when I try to spin up the containers I get the following suggesting that the images still need to be built:
$ docker-compose up -d --no-build
ERROR: Service 'dash_alert_app' needs to be built, but --no-build was passed.
Note that I've configured docker to store images in /mnt/data/docker - here is my /etc/docker/daemon.json file:
{
"graph": "/mnt/data/docker",
"storage-driver": "overlay",
"bip": "192.168.0.1/24"
}
Here is my folder structure:
.
│ docker-compose.yml
└───dash_alert_app
└───nginx
Why is docker-compose not using the images that exist locally?
Looks like you forgot to specify the image key. Also, do you really have to build the image again with docker-compose build or are the existing ones sufficient? If they are, please try this:
version: '3'
services:
dash_alert_app:
image: app_dash_alert_app
container_name: dash_alert_app
restart: always
ports:
- "8000:8000"
command: gunicorn -w 1 -b :8000 dash_histogram_daily_counts:server
nginx:
image: app_nginx
container_name: nginx
restart: always
ports:
- "80:80"
depends_on:
- dash_alert_app
I started learning about docker-compose today and I am having the following issue.
version : '2'
services:
myService1:
build: .
image: newimagename
restart: always
ports:
- "13000:13000"
links :
- database1
command: ["./wait-for-it.sh", "172.17.0.1:3306", "--"]
database1:
image: mydatabaseimage
ports:
- "3306:3306"
restart: always
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_USER=somename
- MYSQL_PASSWORD=somepassword
Details:
The image mydatabaseimage is an image that is built from mariadb image, database entries populated.
myService1 is built from an existing dockerfile for a java project. The problem is that in order for dockerfile to compile the project, it requires database entries. To compile, it will try query some information from 172.17.0.1:3306.
When I run this docker-compose, it will run the dockerfile then it will fail at during java compilation, saying it cannot connect to right database. (I can run this docker-compose only if I already have a database image running in docker container prior...)
I have been looking at the tutorial in here https://docs.docker.com/compose/startup-order/ and tried to use wait-for-it.sh
I am wondering what would I have to do so that database1 image is run first, wait until completed, before myService1 even begins to run its dockerfile?
Thank you.
Try setting depends_on within myService1.
version: "3"
services:
myService1:
build: .
depends_on: database1
I have this docker-compose.yml:
version: '2'
services:
db:
# standard postgres
php:
build:
context: ./
dockerfile: ./docker/php-fpm/Dockerfile.deploy
image: registry.gitlab.com/xxx/php:$CI_COMMIT_SHA
volumes:
- symfonydata:/var/www/symfony
nginx:
build: ./docker/nginx
image: registry.gitlab.com/xxx/nginx:$CI_COMMIT_SHA
ports:
- "80:80"
volumes_from:
- php
links:
- php
volumes:
symfonydata:
In the php-Dockerfile, I add my php code to the volume like:
FROM php:7.1-fpm
COPY . /var/www/symfony/
WORKDIR /var/www/symfony
Ok this works, after docker-compose build I can run
- docker push registry.gitlab.com/xxx/php:$CI_COMMIT_SHA
- docker push registry.gitlab.com/xxx/db:$CI_COMMIT_SHA
- docker push registry.gitlab.com/xxx/nginx:$CI_COMMIT_SHA
and deploy to a registry. When pulling and docker-compose up, the code is there and can be run.
Now, there are other initialization-related things to be done (but only after all services are running).
So I have to execute
docker-compose up
docker exec xxx_php_1 composer install
After that I would like to store my changes to the image. However the changes are applied to the volume (libs installed in vendor). But the command docker tag ... does not affect the volume, I also have no idea how to push the volume to the registry.