Skip to content

Latest commit

 

History

History
232 lines (173 loc) · 8.66 KB

Docker.md

File metadata and controls

232 lines (173 loc) · 8.66 KB

Docker

  • Developer machine → Docker Desktop or Docker Engine Community
  • Small server → Docker Engine Community
  • Critical applications → Docker Engine Enterprise or Kubernetes

Concepts

  • Container: a virtual machine
  • Server: runs multiple Containers
  • Image: a template used to create Container(s)
  • Registry: storage for Images

Commands

docker run --help
  • docker ps -a: lists all containers
  • docker ps: lists the containers that are still running.
  • docker image ls: lists all images
  • docker logs [container ID]: retrieves the logs of a container, even when it has stopped
  • docker inspect [container ID]: gets detailed information about a running or stopped container
  • docker stop: stops a container that is still running
  • docker rm: deletes a container
  • docker image rm: remove image

docker run

docker run hello-world

Useful Docker commands from Causality

Pull down images and start services:

  • docker compose up

Install laravel dependencies:

  • docker compose run --rm composer install

Stopping the local service

  • docker compose stop

Using Composer

  • docker compose run --rm composer install
  • docker compose run --rm composer outdated
  • docker compose run --rm composer update

Using Laravel Artisan

  • docker compose run --rm php php artisan

Running tests

  • docker compose run --rm php php artisan test

Testing

Running all tests:

  • docker compose run --rm php php artisan test

Running a test suite:

  • docker compose run --rm php php artisan test --testsuite Feature

Useful parameters

  • --rm Removes the container after run
  • -d Detach, get the console back after run
  • --build Forces a rebuild of images

All docker commands

The Dockerfile

https://docs.docker.com/engine/reference/builder/

ENTRYPOINT + CMD = default container command arguments

Comparisons

Docker vs Vagrant

  • Vagrant creates and configures lightweight, reproducible, and portable development environments.
  • Docker is an open platform for building, shipping, and running distributed applications.

Where Docker relies on the host operating system, Vagrant includes the operating system within itself as part of the package. One big difference between Docker and Vagrant is that Docker containers run on Linux, but Vagrant files can contain any operating system. That said, Docker does work with non-Linux operating systems. It just needs to run within a Linux virtual machine.

Docker vs Kubernetes

Docker is a containerization platform, and Kubernetes is a container orchestrator for container platforms like Docker.

Kubernetes, Mesos, and Docker Swarm are some of the more popular options for providing an abstraction to make a cluster of machines behave like one big machine, which is vital in a large-scale environment.

Minikube and Tilt

local DNS resolver

192.168.1.247

sudo nano /etc/resolver/minikube-dev

Running:

minikube start
tilt up

Applications on Docker

Postgres SQL on Docker

~/postgres-docker/docker-compose.yml:

version: '3'
services:
	db:
		image: postgres:15
		environment:
			POSTGRES_USER: postgres
			POSTGRES_PASSWORD: [hidden]
			POSTGRES_DB: admin_db  # Just to ensure Postgres starts
		volumes:
			- postgres-data:/var/lib/postgresql/data
			- ./init.sql:/docker-entrypoint-initdb.d/init.sql  # Define the real databases here
		ports:
			- "5432:5432"

volumes:
	postgres-data:

~/postgres-docker/init.sql:

-- CREATE USER "project_user" WITH ENCRYPTED PASSWORD '...'; GRANT ALL PRIVILEGES ON DATABASE "my-database" TO "project_user";
CREATE DATABASE "my-database"; GRANT ALL PRIVILEGES ON DATABASE "my-database" TO postgres;

Commands:

docker-compose down
docker-compose up -d
docker ps -a
docker logs postgres-docker-db-1

psql -h myserver.com -p 5432 -U postgres -W my-database