'Reset localhost:80 port

running containersall containers I've recently started learning docker and after following the tutorial, I ran the following command

docker run -d -p 80:80 docker/getting-started

and open up port localhost:80 and saw the docker getting started page. However, I had to run my client's project, whose port was mapped to localhost:80 as well. On account of this, I'm unable to run my client's project on localhost:80. In addition to that, any instance I randomly open up docker and then switch to localhost:80, it redirects to docker's getting started tutorial. I want to reset this localhost:80 port so that when I run my client's project, I can map them to localhost:80. Any method to rectify the issue?



Solution 1:[1]

First find you container's ID using:

docker ps

Supposing it is e11d9f8bb730, you can now stop and remove the container with:

docker stop e11d9f8bb730
docker rm e11d9f8bb730

Run again your container, this time using a different port:

docker run -d -p 81:80 docker/getting-started

Now your container is running on port 81 and you will be able to run your client's App on port 80.

Solution 2:[2]

You can use docker to map the container port to any port you choose on your local machine. As an example, you could use your docker getting started and map the port to 8080 instead of 80 like this:

docker run -d -p 127.0.0.1:8080:80/tcp docker/getting-started

Solution 3:[3]

All you have to do is stop the container you just started (docker / getting-started). You can open a command prompt, then type this command:

docker container ls

You can see which containers are currently running. For example:

docker containers list

You just need to do this command for the stop container:

docker container stop *yourContainerName*

Solution 4:[4]

My solution to this issue was so simple yet so incredibly annoying, I'm commenting here in case it helps anyone else. It was browser caching. So opening up dev tools and hard refreshing on localhost solved my issue with this.

Solution 5:[5]

You will need to pass the subtype constructor to the static function on the base type.

This is because the base class doesn't (and shouldn't) know anything about the subtypes to know which child constructor to use.

This is an example of how it might look - each subtype defines its own static findAll() method that calls the standard behaviour on the parent class, passing the data and constructor along for the parent to use:

class BaseModel {
    static data: {}[];

    static _findAll<T extends BaseModel>(data: any[], Type): T[] {
        return data.map((x) => new Type(x));
    }

    constructor(readonly attributes) {
    }
}

class Model extends BaseModel {
    static data = [{ id: 1 }, { id: 2 }];

    constructor(attributes) {
        super(attributes);
    }

    static findAll() {
        return BaseModel._findAll(this.data, this);
    }
}

const a = Model.findAll();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 programandoconro
Solution 2 Dominic Holt
Solution 3 Dharman
Solution 4 jmorell
Solution 5 Sly_cardinal