Trying to setup my first Docker container in laravel.
Doing everything exactly like the tutorial, but on my PC I get
The "--host-0.0.0.0" option does not exist.
Dockerfile
FROM php:7.4-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /app
COPY . .
RUN composer install
CMD php artisan serve --host=0.0.0.0
docker-compose.yml
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8000
volumes:
- .:/app
depends_on:
- db
db:
image: library/mysql:5.7.22
environment:
MYSQL_DATABASE: admin
MYSQL_USER: admin
MYSQL_PASSWORD: admin
MYSQL_ROOT_PASSWORD: admin
volumes:
- ./storage/dbdata:/var/lib/mysql
ports:
- 33066:3306
Thanks too #Tolis Gerodimos
https://stackoverflow.com/a/72349936/2240163
docker-compose up --build
Related
I am new to docker and i ran into a problem when i call css and javascript files in php file i found that they are not loaded
Following my code:
docker-compose.yml
version: '3.9'
services:
php-env:
build: .
volumes:
- ./src:/var/www/html
ports:
- "8080:80"
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: airline
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin:latest
restart: always
ports:
- "8081:80"
environment:
- PMA_ARBITRARY=1
dockerfile
FROM php:8.0-apache
WORKDIR /var/www/html
RUN apt-get update -y && apt-get install -y libmariadb-dev
RUN docker-php-ext-install pdo_mysql
my file layout is like this
-resources
--app.css
--app.js
-src
--index.php
I'm fetching the css file like this: <link rel="stylesheet" href="/resources/app.css">
The error I get when I go to the css or js file is:
Not found
The requested URL was not found on this server.
Apache/2.4.54 (Debian) Server at localhost Port 8080
I have managed to get it working on my end, here is the application I created:
/src/index.php
<link rel="stylesheet" href="/resources/app.css">
<?php ?>
<p>Hello World</p>
/resources/app.css:
p {
color: #FF0000
}
Here are the changes I made to the docker-compose.yml and Dockerfile to get it working:
docker-compose.yml
Removed the volume binding for php-env service (since we are going to copy this in the Dockerfile)
version: '3.9'
services:
php-env:
build: .
ports:
- "8080:80"
db:
image: mysql:latest
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: airline
MYSQL_ROOT_PASSWORD: root
phpmyadmin:
image: phpmyadmin:latest
restart: always
ports:
- "8081:80"
environment:
- PMA_ARBITRARY=1
Dockerfile
Copied the /src directory into /var/www/html
Copied the /resources directory into /var/www/html/resources
FROM php:8.0-apache
WORKDIR /var/www/html
COPY ./src ./
COPY ./resources ./resources
RUN apt-get update -y && apt-get install -y libmariadb-dev
RUN docker-php-ext-install pdo_mysql
docker-compose.yml
version: "3.7"
services:
courseshine_redis:
container_name: courseshine_redis
image: redis:latest
command: redis-server --requirepass ${POSTGRES_PASSWORD}
restart: always
env_file: .env
stdin_open: true
ports:
- ${REDIS_PORT}:${REDIS_PORT}
volumes:
- courseshine_redis_data:/data
networks:
- internal
courseshine_db:
container_name: courseshine_db
build:
context: ../..
dockerfile: courseshine_docker/development/courseshine_db/Dockerfile
restart: always
env_file: .env
environment:
- POSTGRES_MULTIPLE_DATABASES=${POSTGRES_DEV_DB},${POSTGRES_TEST_DB}
ports:
- ${COURSESHINE_DB_PORT}:${COURSESHINE_DB_PORT}
volumes:
- courseshine_postgres_data:/var/lib/postgresql/data
- ./courseshine_db:/dockerfile-entrypoint-initdb.d
networks:
- internal
courseshine_pgadmin:
container_name: courseshine_pgadmin
image: dpage/pgadmin4:4.21
restart: unless-stopped
env_file: .env
environment:
- PGADMIN_DEFAULT_EMAIL=${POSTGRES_USER}
- PGADMIN_DEFAULT_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- pgadmin:/var/lib/pgadmin
- courseshine_postgres_data:/var/lib/postgresql/data
depends_on:
- courseshine_db
networks:
- internal
courseshine_api: &api_base
container_name: courseshine_api
build:
context: ../..
dockerfile: courseshine_docker/development/courseshine_api/Dockerfile
env_file: .env
stdin_open: true
volumes:
- ../../courseshine_api:/var/www/courseshine/courseshine_api
- /var/run/docker.sock:/var/run/docker.sock
- bundle_cache:/usr/local/bundle
depends_on:
- courseshine_redis
- courseshine_db
networks:
- internal
courseshine_ui:
container_name: courseshine_ui
build:
context: ../../
dockerfile: courseshine_docker/development/courseshine_ui/Dockerfile
env_file: .env
stdin_open: true
volumes:
- ../../courseshine_ui:/var/www/courseshine_ui
depends_on:
- courseshine_api
networks:
- internal
networks:
internal:
volumes:
courseshine_redis_data:
courseshine_postgres_data:
pgadmin:
bundle_cache:
my docerfile for courseshine_api service
FROM ruby:2.7.1-slim-buster
RUN apt-get update -qq && apt-get install -y build-essential nodejs libpq-dev postgresql-client && rm -rf /var/lib/apt/lists/*
ENV APP_HOME /var/www/courseshine/courseshine_api
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
COPY ./courseshine_api/Gemfile $APP_HOME/Gemfile
COPY ./courseshine_api/Gemfile.lock $APP_HOME/Gemfile.lock
RUN bundle install --path vendor/cache
# Copy the main application.
COPY ./courseshine_api $APP_HOME
# Add a script to be executed every time the container starts.
COPY ./courseshine_docker/development/courseshine_api/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
# Expose port 3000 to the Docker host, so we can access it
# from the outside.
EXPOSE 3000
# The main command to run when the container starts. Also
# tell the Rails dev server to bind to all interfaces by
# default.
CMD ["rails","server","-b","0.0.0.0"]
entrypoint.sh
set -e
rm -f $APP_HOME/tmp/pids/server.pid
exec "$#"
when i hit docker-compose up, the courseshine_api service is not stand and throw Could not find rake-13.0.3 in any of the sources (Bundler::GemNotFound). Why this problem occur and how to fix this ..
I try to configure docker compose for my php project. On deploy I want to update a source code, update composer dependencies and run database migrations.
So I have a docker-compose.yml file:
version: '3.0'
services:
php:
build:
context: .
dockerfile: php/Dockerfile
depends_on:
- postgres
postgres:
image: "postgres:13-alpine"
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB_NAME}
Php container builds from the next Dockerfile:
# Inatall dependensies
RUN apt-get update \
&& apt-get install -y git libicu-dev postgresql-server-dev-all zip libzip-dev postgresql-client\
&& docker-php-ext-install intl pdo pdo_pgsql zip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Copy source files
COPY ./app /var/www/my-site
# Update project files
WORKDIR /var/www/my-site
RUN composer install
RUN php ./yii migrate --interactive=0 # This command needs to connect to the database and fails
CMD [ "php-fpm"]
When I run docker-compose build, I have this error: could not translate host name "postgres" to address: Name or service not known.
How can I take access to database container while other is building?
Both php and postgres need to be on same network and php can access postgres using container_name which is postgres. depends_on will make sure postgres get starts before php.
version: '3.0'
services:
php:
build:
context: .
dockerfile: php/Dockerfile
restart: on-failure
depends_on:
- postgres
networks:
- test-network
postgres:
container_name: 'postgres'
image: "postgres:13-alpine"
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB_NAME}
networks:
- test-network
networks:
test-network:
driver: bridge
I have a Dockerfile that runs perfectly on it's own.
But when I run it from docker-compose up --build
I get: $GOPATH/go.mod exists but should not
Below is a snippet of terminal output.
Successfully tagged app_app:latest
Starting golang_db ... done
Starting golang_app ... done
Attaching to golang_db, golang_app
golang_app | $GOPATH/go.mod exists but should not
.
.
golang_db | Version: '5.6.48' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
golang_app exited with code 1
Any suggestions?
#docker-compose.yml
version: '3'
services:
db:
build:
context: ./MySQL
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_db
MYSQL_USER: docker
MYSQL_PASSWORD: docker
container_name: golang_db
ports:
- "3306:3306"
tty: true
app:
build:
context: ./Go
volumes:
- "./Go:/go"
container_name: golang_app
ports:
- "9000:9000"
tty: true
depends_on:
- db
#Go/Dockerfile
FROM golang:alpine AS builder
ENV GO111MODULE=on
RUN mkdir /app
ADD . /app/
WORKDIR /app
COPY ./structs.go .
COPY ./handlers.go .
COPY ./server.go .
COPY ./favicon.ico .
COPY ./assets /assets
RUN go mod init stuff.com
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(ls -1 *.go)
EXPOSE 9000
CMD ["go", "run", "."]
#MySQL/Dockerfile
FROM mysql:5.6
COPY test.sql /docker-entrypoint-initdb.d/test.sql
In the root of your GOPATH no packages are expected. The expectation is usually to have a subdirectory src/github.com/someproject/somerepo, which is most likely the root cause of the warning
I sorted it out, the Dockerfile above has been updated.
When I exec into the created container, not the files in . are copied but the folder is coppied into /var/www/project
So I wan't to have all my files in the project folder but instead the folder containing the files is copied to project.
I am using Mac OS, Docker 18.06.1-ce
/docker/docker-compose.yml
version: "3"
services:
nginx:
build:
context: ./../
dockerfile: docker/nginx/Dockerfile
ports:
- 8081:80
volumes:
- ../.././:/var/www/project/
networks:
- symfony
fpm:
build:
context: ./../
dockerfile: docker/php/Dockerfile
volumes:
- ../.././:/var/www/project/
networks:
- symfony
mysql:
image: mysql:5.6
environment:
- MYSQL_ROOT_PASSWORD=root
ports:
- 3311:3306
networks:
- symfony
networks:
symfony:
/docker/nginx/Dockerfile
FROM nginx:1.14
COPY ./docker/nginx/default.conf /etc/nginx/conf.d/
COPY . /var/www/project
/docker/php/Dockerfile
FROM php:7.2-fpm
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
COPY . /var/www/project
WORKDIR /var/www/project/