Search code examples
dockerdocker-composecicd

How to runner docker containers without any network access


I use docker-compose to run containers to build different components as part of my CI/CD pipeline. Recently I have started noticing that the build pipeline fails sometimes while trying to download build dependencies from the internet in run time, as sometimes these links are down.

To fix this I want to test running the docker container which builds these applications without any internet connection, I want to include all the required dependencies which are downloaded at runtime as part of the docker image.

Can someone let me what change should I make in my docker-compose so that the container starts without any network access?

Here is a sample of my docker-compose file:

version: "3.7"
services:
build-component-1:
    image: base-image:1
    network_mode: host
    volumes:
        - "$PWD:/build-dir"
    command: ./build.sh build_app1
    working_dir: /build-dir
    privileged: true
    environment:
        - USER=root
        - VAR1=$VAR1
    env_file:
        - version.txt

Solution

  • Found the answer here - https://docs.docker.com/compose/compose-file/compose-file-v3/

    I have to replace network_mode: host with network_mode: none in the docker-compose file.