Skip to main content

API in Docker

Installing the CodeChat API on Docker

Docker is a popular platform for developing, delivering, and running applications using containers. Following the instructions below will allow you to run the CodeChat API inside a Docker container, providing an isolated and consistent environment. Here is the breakdown of each step:

  1. Docker Installation:

    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    sudo usermod -aG docker ${USER}
    • This set of commands installs Docker on your system:
      • curl -fsSL https://get.docker.com -o get-docker.sh: Downloads the Docker installation script.
      • sudo sh get-docker.sh: Runs the downloaded script to install Docker.
      • sudo usermod -aG docker ${USER}: Adds the current user to the Docker group, allowing you to run Docker commands without needing sudo.
  2. Building the Docker Image:

    docker build -t codechat_v2/api .
    • This command builds a Docker image for the CodeChat API application based on the Dockerfile present in the current directory (.). The image is named codechat_v2/api.
  3. Creating a Network for the Container:

    docker network create api_network --driver bridge
    • This command creates a Docker network called api_network using the bridge network driver. Docker networks allow containers to communicate with each other in an isolated and secure manner.
  4. Docker Container Execution:

    docker run --restart 'always' --name 'api_codechat' --mount 'type=bind,source=./instances,target=/codechat/instances' --publish '8083:8083' --network 'api_network' codechat_v2 /api
    • This command runs a Docker container using the codechat_v2/api image created previously:
      • --restart 'always': Ensures that the container is automatically restarted if it stops. This is useful in case of server failures or restarts.
      • --name 'api_codechat': Names the container api_codechat.
      • --mount 'type=bind,source=./instances,target=/codechat/instances': Mounts a volume, linking the host's ./instances folder to the /codechat/instances path within the container . This is useful for data persistence or for sharing files between the host and container.
      • --publish '8083:8083': Maps host port 8083 to container port 8083, allowing API access.
      • --network 'api_network': Connects the container to the api_network network created in the previous step.