Docker commands
Dockerfile: think of it as the script portion of package.json (of course it is a script file that Docker will use to create image, container etc)
.dockerignore: same as .gitignore
-
lists all containers
docker container ls
-
lists all images
docker image ls
-
creates a new image which copies files from current directory (the . signifies this, replace as necessary)
docker build -t newImageName .
-
runs image ‘imageName’ on port 4000 inside Docker container and then forward that port to host device’s port 8000
docker run -it -p 8000:4000 imageName
-
creates a container and image for MySQL server, maps the container’s port 3306 to the host device’s port 3307 and sets environment variable MYSQL_ROOT_PASSWORD as password123. Docker tries to find image ‘mysql’, and downloads one if it can’t find locally
docker run --name newContainerName -p 3307:3306 -e MYSQL_ROOT_PASSWORD=password123 mysql
-
allows you to enter the container with bash, just like you’d SSH into a VM or Server. To switch to SSH, you just have to type ssh at the end instead of bash
docker exec -it containerImageName bash