Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 656 Bytes

File metadata and controls

39 lines (24 loc) · 656 Bytes

Ports And Volumes

Level

Beginner to Intermediate.

Ports

A container may listen on port 8000, but that does not automatically make it reachable from the host.

Map a host port:

docker run -p 8080:8000 my-api:v1

Traffic path:

host:8080 -> container:8000

Volumes

Container writable storage is disposable.

Use a volume for data that should survive container replacement:

docker run -v app-data:/data my-api:v1

Common Mistakes

  • reversing host and container ports
  • storing database data only inside the container
  • mounting over files required by the image
  • assuming EXPOSE publishes a port