Docker Building

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

docker buildx create --name my-builder

docker buildx use my-builder

# Split architectures so that we don't get any manifest errors, actually we only
have to build images using the AMD64 archictector since we can compose other images
locally
# run each command from the folder where the Dockerfile is located
docker buildx build --platform linux/amd64 -t solar-mysql:amd64 --load .
docker buildx build --platform linux/amd64 -t solar-nginx:amd64 --load .
docker buildx build --platform linux/amd64 -t solar-php:amd64 --load .

# running the splitter architecture builds


docker run -d \
--name mysql-container \
-p 3306:3306 \
--network bridge \
-v $(pwd)/mysql:/var/lib/mysql \
-v $(pwd)/docker/mysql/config:/etc/mysql/conf.d \
-v $(pwd)/logs/mysql:/var/log/mysql \
solar-mysql:amd64

# composing also works with the included compose file to simultaneous configure all
dockers

# saving the docker images


docker save -o solar-php.docker solar-php:amd64
docker save -o solar-mysql.docker solar-mysql:amd64
docker save -o solar-nginx.docker solar-nginx:amd64

# loading docker images on linux after copying


lspe001491.eu.rabonet.com
Sudo docker load -i solar-php.docker
Sudo docker load -i solar-mysql.docker
Sudo docker load -i solar-nginx.docker

# prepare linux server (first time only)


I added the following to /etc/sysctl.conf:
net.ipv4.ip_forward=1

# composing docker on linux and running (including auto start)


Sudo docker compose -f "docker-compose_all_AMD64.yml" up -d --build

# Useful docker commands


Sudo docker ps #shows all running dockers
Sudo docker container ls # shows all containers
Sudo docker rm <CONTAINERNAME> #removes a container
Sudo docker stop <CONTAINERNAME> #starts a container
Sudo docker rmi <IMAGENAME> #deletes a docker image

TRIED BUT DIDN't WORK


# Export to TAR but cannot import or run correctly
docker buildx build --platform linux/amd64,linux/arm64/v8 -t
solar_mysql_multiarch:latest --output type=tar,dest=solar_mysql_multiarch.tar .
# Load multi arch does not work
docker buildx build --platform linux/amd64,linux/arm64/v8 -t
solar_mysql_multiarch:latest --load .

Use docker import for image exported by docker export.


Use docker load for image exported by docker save.

# This command should load the image but gives errors


docker load -i solar_mysql_multiarch.tar
#This command creates a new docker image, and works
cat solar_mysql_multiarch.tar | docker import - solar-mysql-multiarch

You might also like