Skip to content

Using Coastseg with Docker

Starting CoastSeg with Docker

  1. Launch Docker Desktop

    • After installation, launch Docker Desktop. It will start the Docker Engine and display its status.
  2. Verify Docker Engine is Running

    • Open a terminal (or PowerShell on Windows) and run:
      1
      docker info
      
    • This confirms that Docker is running correctly.
  3. Change to the CoastSeg Directory

    • Open a terminal (or PowerShell on Windows) and run:
      1
      cd <CoastSeg_Directory>
      
    • Note: Replace <CoastSeg_Directory> with the path to the CoastSeg directory.
  4. Update the compose.yml file

    • Open the compose.yml file in a text editor and edit the following lines to be the location of your CoastSeg directory:
    • If you don't change these lines, the container will not be able to access the data and models.
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      services:
        coastseg:
          build: 
            context: .
            dockerfile: dockerfile
          ports:
            - "8888:8888"
          runtime: nvidia
          stdin_open: true
          tty: true
          command: /bin/bash
          volumes:
            - type: bind
              source: //c/development/doodleverse/coastseg/CoastSeg/data # edit this line
              target: //coastseg/data
            - type: bind
              source: //c/development/doodleverse/coastseg/CoastSeg/sessions # edit this line
              target: //coastseg/sessions
            - type: bind
              source: //c/development/doodleverse/coastseg/CoastSeg/logs # edit this line
              target: //coastseg/logs
            - type: bind
              source: //c/development/doodleverse/coastseg/CoastSeg/tide_model # edit this line
              target: //coastseg/tide_model
            - type: bind 
              source: //c/development/doodleverse/coastseg/CoastSeg/src
              target: //coastseg/src
          environment:
            - JUPYTER_ENABLE_LAB=yes
          deploy:
            resources:
              reservations:
                devices:
                  - driver: nvidia
                    count: all
                    capabilities: [gpu]
      
    • Here is an example, lets says you downloaded CoastSeg to C:/users/yourname/CoastSeg, then the lines would look like this:
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      services:
        coastseg:
          build: 
            context: .
            dockerfile: dockerfile
          ports:
            - "8888:8888"
          runtime: nvidia
          stdin_open: true
          tty: true
          command: /bin/bash
          volumes:
            - type: bind
              source: //c/users/yourname/CoastSeg/data # edit this line
              target: //coastseg/data
            - type: bind
              source: //c/users/yourname/CoastSeg/sessions # edit this line
              target: //coastseg/sessions
            - type: bind
              source: //c/users/yourname/coastseg/CoastSeg/logs # edit this line
              target: //coastseg/logs
            - type: bind
              source: //c/users/yourname/CoastSeg/tide_model # edit this line
              target: //coastseg/tide_model
            - type: bind 
              source: //c/users/yourname/CoastSeg/src
              target: //coastseg/src
          environment:
            - JUPYTER_ENABLE_LAB=yes
          deploy:
            resources:
              reservations:
                devices:
                  - driver: nvidia
                    count: all
                    capabilities: [gpu]
      
  5. Create the Docker Container for CoastSeg

    • bash docker-compose up -d --build -- -d flag runs the containers in detached mode, meaning they run in the background.

    • Sample Output:

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
          Just set COMPOSE_BAKE=true
          [+] Building 401.5s (10/10) FINISHED                                                               docker:desktop-linux
          => [coastseg internal] load build definition from dockerfile                                                      0.0s
          => => transferring dockerfile: 891B                                                                               0.0s
          => [coastseg internal] load metadata for ghcr.io/prefix-dev/pixi:latest                                           1.9s
          => [coastseg internal] load .dockerignore                                                                         0.0s
          => => transferring context: 661B                                                                                  0.0s
          => [coastseg 1/4] FROM ghcr.io/prefix-dev/pixi:latest@sha256:100cab99fc052041039e92761a4adcec8fe0b2fadeb4cc292b9  2.3s
          => => resolve ghcr.io/prefix-dev/pixi:latest@sha256:100cab99fc052041039e92761a4adcec8fe0b2fadeb4cc292b9db525007d  0.0s
          => => sha256:f3bd00dddb19b7013a3301c622ec9c2d9f82028e37713a33b2d020c94a1e30f3 2.15kB / 2.15kB                     0.0s
          => => sha256:04cb8c9dec2ddb1fa01a179ca4c6c11e38836666a7195d16e6be9fd1c558275f 23.27MB / 23.27MB                   1.9s
          => => sha256:100cab99fc052041039e92761a4adcec8fe0b2fadeb4cc292b9db525007df2d2 683B / 683B                         0.0s
          => => sha256:acae18dbecdd31cf9449c6021590872f876721f4e86bed47beb4eec91b8074b4 703B / 703B                         0.0s
          => => extracting sha256:04cb8c9dec2ddb1fa01a179ca4c6c11e38836666a7195d16e6be9fd1c558275f                          0.3s
          => [coastseg internal] load build context                                                                        97.2s
          => => transferring context: 3.57GB                                                                               97.2s
          => [coastseg 2/4] WORKDIR /coastseg                                                                               0.1s
          => [coastseg 3/4] COPY ./ .                                                                                       4.3s
          => [coastseg 4/4] RUN pixi install --locked                                                                     279.5s
          => [coastseg] exporting to image                                                                                 18.4s
          => => exporting layers                                                                                           18.4s
          => => writing image sha256:de510860e74d79dae2178e489e92596f509f9753534ba8aaca1dcf46470c79e2                       0.0s
          => => naming to docker.io/library/coastseg_docker-coastseg                                                        0.0s
          => [coastseg] resolving provenance for metadata file                                                              0.0s
          [+] Running 3/3
           coastseg                              Built                                                                     0.0s
           Network coastseg_docker_default       Created                                                                   0.0s
           Container coastseg_docker-coastseg-1  Started                                                                   0.9s
      

    • Note: Replace <CoastSeg_Directory> with the path to the CoastSeg directory.
  6. List the Running Docker Containers

    • bash docker ps
    • This command lists the running Docker containers.
    • Sample Output
      1
      2
      3
      PS C:\development\doodleverse\coastseg\Coastseg_docker> docker ps
      CONTAINER ID   IMAGE                      COMMAND       CREATED         STATUS         PORTS                    NAMES
      a605a9e40ccf   coastseg_docker-coastseg   "/bin/bash"   3 minutes ago   Up 3 minutes   0.0.0.0:8888->8888/tcp   coastseg_docker-coastseg-1
      
  7. Open the Running Container

    • bash docker exec -it a605a9e40ccf /bin/bash
    • This command opens an interactive terminal session inside the running container.
    • Sample Output
    • bash PS C:\development\doodleverse\coastseg\Coastseg_docker> docker exec -it a605a9e40ccf /bin/bash root@a605a9e40ccf:/coastseg#
    • root@a605a9e40ccf:/coastseg# is the terminal prompt inside the running container.
  8. Activate the CoastSeg Environment

    1
      pixi shell --locked 
    
    - This command activates the CoastSeg environment inside the container using pixi - --locked flag ensures that the environment is locked to the exact versions specified in the pixi.lock file. - Sample Output
    1
    2
      root@a605a9e40ccf:/coastseg# pixi shell --locked
      (coastseg) root@a605a9e40ccf:/coastseg#
    
    - (coastseg) indicates that the coastseg environment is active.

  9. Run a notebook in the container

    1
      root@a605a9e40ccf:/coastseg# jupyter lab SDS_coastsat_classifier.ipynb --ip=0.0.0.0 --allow-root --no-browser
    

    • This command runs the Jupyter notebook SDS_coastsat_classifier.ipynb in the container and allows access from the host machine.
  10. Stop and Remove the Running Container

    1
    2
    3
    docker ps
    docker stop [container_name_or_id]
    docker rm [container_name_or_id]
    

    • This command stops and removes the running container.