I've got some issues with Docker.
Here is my docker-compose.yml
:
services:
web-server:
build:
context: ./apache
volumes:
- ../src:/var/www
- ./conf:/etc/apache2/sites-enabled
ports:
- "80:80"
- "443:443"
networks:
- internal
database:
build:
context: ./database
ports:
- "3306:3306"
networks:
- internal
networks:
internal:
After running docker-compose up --build
I have this error:
[+] Running 2/4
✔ database Built 0.0s
✔ web-server Built 0.0s
- Container docker-web-server-1 Creating 0.0s
- Container docker-database-1 Creating 0.0s
Error response from daemon: {"message":"No such image: docker-database"}
I have no idea why it can't find the image automatically created by Docker.
UPD Here is my Dockerfiles. And i need some extra text to apply this post because it warnings me that this post is mostly code...
./apache/Dockerfile
FROM ubuntu
RUN apt update -y && apt upgrade -y
RUN apt install -y apache2 php
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php
RUN php -r "unlink('composer-setup.php');"
RUN mv composer.phar /usr/local/bin/composer
WORKDIR /var/www
CMD ["apachectl"]
EXPOSE 80 443
./database/Dockerfile
FROM ubuntu
RUN apt update -y && apt upgrade -y
RUN apt install -y mysql-server
CMD ["mysqld_safe"]
EXPOSE 3306
Your build statements are wrong in your compose file. Instead of
build:
context: ./apache
you want
build: ./apache
By specifying the context, Docker uses the Dockerfile in the directory with your compose file but builds it with the context of the directory you specify.
Change your compose file to
services:
web-server:
build: ./apache
volumes:
- ../src:/var/www
- ./conf:/etc/apache2/sites-enabled
ports:
- "80:80"
- "443:443"
networks:
- internal
database:
build: ./database
ports:
- "3306:3306"
networks:
- internal
networks:
internal:
and it should work.