-
Notifications
You must be signed in to change notification settings - Fork 0
Docker
Docker is used to run software applications in isolated environments called containers, which are created from Docker images. These containers encapsulate all the software dependencies, such as libraries, tools, and even the operating system version, required to run an application.
A Docker image is a snapshot of a complete software environment. It includes everything needed to run a piece of software:
- Application code
- Dependencies
- (Optionally) a minimal operating system
Docker provides a streamlined way to share development environments, allowing others to run your code without manually replicating the same setup. This is especially valuable because software dependencies can degrade or become incompatible with other packages over time. Docker mitigates these issues by enabling you to capture your exact setup with specific versions of different packages with a Dockerfile.
To build a Docker image, you write a Dockerfile, which acts as a blueprint. This file contains a sequence of instructions that specify how to assemble the image:
- Selecting a base image
- Installing dependencies
- Copying over files
Example:
FROM python:3.10
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
...
To run code using a Docker image, you launch a container, which is a runtime instance of that image. Inside a container, you can operate almost exactly as if you were using a native environment.
However, containers are volatile by default, i.e. any changes made inside them (such as installing additional packages or modifying files) will be lost once the container is stopped or deleted, unless those changes are explicitly saved or externalized like mounting local directories.
-
Dockerfile: Script to build a Docker image
-
Docker Image: Base copy of a software environment
-
Container: Runnable instance of an image
If you are using a Linux OS like Ubuntu, you can use our linux_docker_setup.sh
shell script to automatically download and setup docker for you!
You can download docker-desktop via the following link
To build the docker image, run the following command in the docker directory. This will take a while to build, but you only need to do it once unless you change the dockerfile.
sudo docker compose --build
To access the container based on the image we made, open a terminal in the docker directory and run :
sudo docker compose up
This will create a container using the setup flags specified in docker-compose.yml
. While this container is running, you can access it by:
- Opening a new terminal
- Run the following command
sudo docker compose exec halley bash
This should place you in the rover25_ws directory. Afterwards you should run the following two commands:
colcon build
source install/setup.bash
Now you should able to work and access our repo as if you have your own Linux setup:)
In the docker container, if you are unable to see src
in rover25_ws make sure that docker is a part of the sudo group using the following lines:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Then try relaunching the container using
docker compose up # In the src/docker directory
docker compose exec halley bash # In a new terminal