title: Docker-compose up works, but using visual studio code dev container doesn't
body: <p>I am new to Docker and containers in general. I played around and got to a point, where I do not get any further. I searched through other questions but I couldn't see the right question (or understand) the answers. So I hope you can help me.</p>
  <p>I do have two containers, running php:7.4-apache and mariadb. They are working fine and if I use a docker compose file, I can start everything well with <code>docker-compose up -d</code>.</p>
  <p>Here the docker compose file (remember, this is my first file, so I have not that much knowledge about it):</p>
  <pre><code>version: '3.1'
  
  services:
    mariadb:
      image: mariadb:latest
      environment:
        - MYSQL_DATABASE=mydb
        - MYSQL_USER=myuser
        - MYSQL_PASSWORD=secret
        - MYSQL_ROOT_PASSWORD=docker
      ports:
        - &quot;3306:3306&quot;
      volumes:
        - ./database/storage
        - ./database/src:/usr/src
      restart: always
  
    php:
      image: php:7.4-apache
      ports:
        - 80:80
      volumes:
        - ./php/src:/var/www/html/
      restart: always
  </code></pre>
  <p>My &quot;project structure&quot; looks like this:</p>
  <p><a href="https://i.stack.imgur.com/tPHDk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tPHDk.png" alt="Project structure" /></a></p>
  <p>If I start now the dev container, I can choose to use the docker-compose file. I did this, and the first thing I didn't understand is, that I have to choose between those two services (php/mariadb).
  So I used php for a try. It starts running, and I can see the container with <code>docker ps</code>.
  However, if I want to connect to the php-website via <code>localhost:80</code> and see my &quot;website&quot;, I do not get any connections.
  I expected the same behavior like if I would use the docker-compose up. But this doesn't happen. Here is the devcontainer.json, it might help:</p>
  <pre><code>// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
  {
      &quot;name&quot;: &quot;Existing Docker Compose (Extend)&quot;,
  
      // Update the 'dockerComposeFile' list if you have more compose files or use different names.
      // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
      &quot;dockerComposeFile&quot;: [
          &quot;..\\Docker-compose.yml&quot;,
          &quot;docker-compose.yml&quot;
      ],
  
      // The 'service' property is the name of the service for the container that VS Code should
      // use. Update this value and .devcontainer/docker-compose.yml to the real service name.
      &quot;service&quot;: &quot;php&quot;,
  
      // The optional 'workspaceFolder' property is the path VS Code should open by default when
      // connected. This is typically a file mount in .devcontainer/docker-compose.yml
      &quot;workspaceFolder&quot;: &quot;/workspace&quot;,
  
      // Set *default* container specific settings.json values on container create.
      &quot;settings&quot;: {
          &quot;terminal.integrated.shell.linux&quot;: null
      },
  
      // Add the IDs of extensions you want installed when the container is created.
      &quot;extensions&quot;: [],
  
      // Use 'forwardPorts' to make a list of ports inside the container available locally.
      &quot;forwardPorts&quot;: [80],
  
      // Uncomment the next line if you want start specific services in your Docker Compose config.
      // &quot;runServices&quot;: [],
  
      // Uncomment the next line if you want to keep your containers running after VS Code shuts down.
      // &quot;shutdownAction&quot;: &quot;none&quot;,
  
      // Uncomment the next line to run commands after the container is created - for example installing curl.
      // &quot;postCreateCommand&quot;: &quot;apt-get update &amp;&amp; apt-get install -y curl&quot;,
  
      // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
      // &quot;remoteUser&quot;: &quot;vscode&quot;
  }
  
  </code></pre>
  <p>As you can see, I tried forwarding the port 80, but this didn't work either. It is also confusing, that the <em>docker-compose.yml</em> within the <em>.devcontainer</em> folder is not the same yml as my original <em>Docker-compose.yml</em>.</p>
  <p>I have no idea on what to do next. I hope, that I can use visual studio code for making simple php scripts within this container and later on, connect to the mariadb. Both mariadb and php should run in seperate containers. Well, at least that was my hope.</p>
  <p><em>---Additional information---</em></p>
  <p>To show what VisualStudio Code is showing me, here some screenshots:</p>
  <p><a href="https://i.stack.imgur.com/eRbpP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eRbpP.png" alt="enter image description here" /></a></p>
  <p>I choose to open folder in container.</p>
  <p><a href="https://i.stack.imgur.com/DV2hJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DV2hJ.png" alt="enter image description here" /></a></p>
  <p>Then I choose the <em>Docker-compose.yml</em> (Which is working fine if I use <code>docker-compose up</code>).</p>
  <p><a href="https://i.stack.imgur.com/00kQT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/00kQT.png" alt="enter image description here" /></a></p>
  <p>As you can see, it is now asking me about which service I want to select. Which if funny, because I would like both service to run ... But in this scenario, it would be fine if I could change via VS-Code the php scripts.</p>
  <p>Thanks for the help</p>
  <p>-GreNait</p>