I'm new to devcontainer and I can't figure out why my apache would forward to port 8000. I tried everything, but it can either not find the requested path, or I dont have permission. Which I tried add the user to www-data. Nothing works.
Docker-compose file: I tried to change the path to the workspace, and I had to add the command to start apache.
version: "3.4"
services:
app:
build:
context: .
dockerfile: Dockerfile
args:
UID: 1001
restart: unless-stopped
ports:
- "8000:80"
volumes:
- ./:/var/www/html
#- workspace:/workspace
- /var/run/docker.sock:/var/run/docker.sock
command: /bin/sh -c "service apache2 start && while sleep 1000; do :; done"
environment:
- APACHE_RUN_USER=#1001
- APACHE_RUN_GROUP=#1001
devcontainer
// See https://aka.ms/vscode-remote/devcontainer.json for format details.
{
"name": "PHP",
"dockerComposeFile": ["docker-compose.yml"],
"service": "app",
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"applicationUrl": "http://*:8000",
"php.validate.executablePath": "/usr/local/bin/php",
"editor.tabSize": 4,
"workbench.colorTheme": "Quiet Light"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"xdebug.php-debug",
"bmewburn.vscode-intelephense-client",
"mrmlnc.vscode-apache"
]
}
},
"forwardPorts": [8000:80],
//"appPort": [80],
// Uncomment this like if you want to keep your containers running after VS Code shuts down.
// "shutdownAction": "none",
//"workspaceMount": "src=${localWorkspaceFolder},dst=/var/www/html,type=bind,consistency=cached",
//"workspaceFolder": "/var/www/html",
"postCreateCommand": "composer install",
"remoteUser": "php-apache",
"containerUser": "php-apache"
}
Dockerfile, as said I tried to add the user to www-data, I still think I need to do that, the command apache-foreground don't work properly
# [Choice] PHP version (use -bullseye variants on local arm64/Apple Silicon): 8-apache-bullseye, 8.1-apache-bullseye, 8.0-apache-bullseye, 7-apache-bullseye, 7.4-apache-bullseye, 8-apache-buster, 8.1-apache-buster, 8.0-apache-buster, 7-apache-buster, 7.4-apache-buster
ARG VARIANT=8.1-apache-bullseye
FROM php:${VARIANT}
ARG USERNAME=php-apache
ARG USER_UID=1001
ARG USER_GID=$USER_UID
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
RUN apt-get update && apt-get install -y zip libzip-dev git inetutils-ping
RUN docker-php-ext-install \
zip
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY apache-vhost.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite headers
RUN a2dissite *
RUN a2ensite 000-default.conf
VOLUME [ "/var/www/html",]
EXPOSE 8000
CMD [ "apache2-foreground" ]
hostfile
<VirtualHost *:80>
DocumentRoot /var/www/html/public
# LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I appreciate any correction, I tried googling it, but there are few examples, and none of them only got me another error.