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_run.sh

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

docker-compose.yml

version: '3'
services:
    web:
        image: web
        build: .
        ports:
            - "80:80"
            - "443:443"
            - "3316:3306"
        volumes:
            - "../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    0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:3307->3306/tcp   <name>
$ docker-compose ps
Name            Command               State                                Ports                              
---------------------------------------------------------------------------------------------------------------
web   /usr/local/scripts/start_s ...   Up      0.0.0.0:3316->3306/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp

What am I missing?

Source: StackOverflow