Docker Quick Start
Docker concepts
- A docker container is kind of a virtual machine except it only runs a lightweight command line version of Linux and uses the host computer's resources to function. It's supposed to be lightweight.
- The
docker compose
command is the equivalent of a makefile in C- You can use docker run to start a container with literally multiple lines of options OR put all of those options in a docker-compose.yml file and run
docker compose up
instead.
- You can use docker run to start a container with literally multiple lines of options OR put all of those options in a docker-compose.yml file and run
- The
docker-compose.yml
file describes how the docker container is built.- It can bundle docker images together
Start/stop container
You can either use Docker Desktop's Dashboard or the command line.
Docker Desktop:
- Go to the "containers" tab, click the start/stop button next to the container called 'backend' or 'laravel.test-1'
Command line:
# start container
sail up -d
docker compose up -d
# stop container
sail down
docker compose down
Show a list of containers
You can either use Docker Desktop's Dashboard or the command line.
- Docker Desktop:
- Go to the "container" tab to see a list of all containers, both running and stopped
- Command line:
- Show active containers only:
docker ps
- Show ALL containers, both active and inactive:
docker ps -a
- Show active containers only:
Get container id
You can either use Docker Desktop's Dashboard or the command line.
- Docker Desktop
- Go to the "container" tab.
- Find backend > laravel.test-1 container
- Underneath the container title is a string of characters like
47e98223b7bf
. That's the container id. - Copy the container id
- Command line
- Run
docker ps -a
to show all containers - Find the container id and copy it
- Run
Get container name
Easiest and surest way is to use the command line
- Run
docker ps -a
to show all the containers - Find the container name and copy it
Access the docker container's command line
You can either use Docker Desktop's Dashboard or the command line.
From Docker Desktop
- Go to the "containers" tab
- Make sure that the laravel container is RUNNING
- Click into the laravel container
- Click the "terminal" tab (for mac users) or the "exec" tab (for windows users)
- Run
bash
to change the shell to bash - Start running commands as if it's your local machine. Meaning, don't use
sail
commands or docker commands, just use the original commands- Example: run
php --version
instead ofsail php --verion
ordocker exec -it <container-id/name> php --version
- Example: run
From Command line
- Run
docker exec -it <container-id/name> bash
to enter the command line inside the docker container-it
means interactive
- Start running commands as if it's your local machine. Meaning, don't use
sail
commands or docker commands, just use the original commands- Example: run
php --version
instead ofsail php --verion
ordocker exec -it <container-id/name> php --version
- Example: run