July 30, 2021 devlog
- Worked on Dockerizing a Vue project at work
TIL
Docker has a lot of command line configs to keep track of, but they’re really important. These refer to the docker run command:
-
-pis used to map ports between the Docker container and the host machine. I initially expected theEXPOSEcommand in the Dockerfile to do this for me, but I learned that mostly just specifies which ports will need mapped. To map port 8080 between my host and the Docker container I needed to add-p 8080:8080to mydocker runcommand. To map additional ports just add morepflags, egdocker run -p 8080:8080 -p 8081:8081 my_image. -
--rmautomatically removes the container when it stops (egdocker run --rm my_image). Without this you need to manually go in and remove stopped containers, which will sit on your machine indefinitely and take up space.
Docker uses a special internal IP address to refer to the container’s host on OSX, which is 192.168.65.2. I’m currently using that IP instead of localhost in a few JS files that make HTTP requests to an API server running on my host machine. Here is the site I learned this from.