What is the difference between docker run -p and ports in docker-compose.yml?

I would like to use a standard way of running my docker containers. I have have been keeping a docker_run.sh file, but docker-compose.yml looks like a better choice. This seems to work great until I try to access my website running in the container. The ports don’t seem to be set up correctly.

Using the following docker_run.sh, I can access the website at localhost. I expected the following docker-compose.yml file to have the same results when I use the docker-compose run web command.


docker build -t web .
docker run -it -v /home/<user>/git/www:/var/www -p 80:80/tcp -p 443:443/tcp -p 3316:3306/tcp web


version: '3'
        image: web
        build: .
            - "80:80"
            - "443:443"
            - "3316:3306"
            - "../www:/var/www"

Further analysis

The ports are reported as the same in docker ps and docker-compose ps. Note: these were not up at the same time.

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                              NAMES
<id>        web      "/usr/local/scripts/…"   About an hour ago   Up About an hour>80/tcp,>443/tcp,>3306/tcp   <name>
$ docker-compose ps
Name            Command               State                                Ports                              
web   /usr/local/scripts/start_s ...   Up>3306/tcp,>443/tcp,>80/tcp

What am I missing?

Source: StackOverflow