Aliyaminim / karatsuba-multiplication

problem_mpk
0 stars 0 forks source link

Remove direct docker container ID reference #2

Open sin-diesel opened 7 months ago

sin-diesel commented 7 months ago

https://github.com/Aliyaminim/karatsuba-multiplication/blob/0bf42bd39e0dd90f50f26e27f90d524e51111d00/Makefile#L7

The created ID is machine and user specific, and it will differ from one launch from another. You must not rely on conatiner ID, instead, docker containers have names by which you can reference them.

Take a look at following: https://docs.docker.com/get-started/

When containerizing your application, you must first describe the image for your container. Image is created using Dockerfile and essentially is some sort of a binary file from which the docker can create containerized environment.

When you have the image (either on the host, or somewhere on the remote), you can run the container from it using docker run command:

export WORKDIR=$HOME
export CONTAINER=rv_tools_experiments                                       
export IMAGE=ghcr.io/riscv-technologies-lab/rv_tools_image:1.0.1
docker run --interactive \
      --tty \
      --detach \
      --env "TERM=xterm-256color" \
      --mount type=bind,source="$WORKDIR",target="$WORKDIR" \
      --name $CONTAINER \
      --ulimit nofile=1024:1024 \
      --user "$(id -u $USER):$(id -g $USER)" \
      --network=host \
      --workdir $WORKDIR \
      $IMAGE

After running the container, you can reference it by its name:

docker exec -it $CONTAINER bash

You can also stop the container:

docker container stop $CONTAINER
docker container ps -a
CONTAINER ID   IMAGE                                                 COMMAND       CREATED         STATUS                            PORTS     NAMES
5be658ff3baa   ghcr.io/riscv-technologies-lab/rv_tools_image:1.0.1   "/bin/bash"   8 minutes ago   Exited (137) About a minute ago             rv_tools_experiments

When you want to rerun the container, you don't have to create it from the docker image again. The container is already created and simply need to be restarted:

docker container start rv_tools_experiments