How to attach container to an existing network using its id #4567
              
                
                  
                  
                    Answered
                  
                  by
                    kiview
                  
              
          
                  
                    
                      ratcashdev
                    
                  
                
                  asked this question in
                Q&A
              
            -
| I'd like to attach a newly pulled container to an existing set of containers (started externally using docker compose) running on network 'docker_default'. Or simply allow the compose module to attach to an existing (and running) compose 'project' started from outside and create the socat container inside it so that we are able to do port maps. | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            kiview
          
      
      
        Oct 11, 2021 
      
    
    Replies: 1 comment 3 replies
-
| You can instantiate a new  Network n = new Network() {
    @Override
    String getId() {
        return "existingId" // use id of external network
    }
    @Override
    void close() throws Exception {
    }
    @Override
    Statement apply(Statement base, Description description) {
        return null
    }
}
container.withNetwork(n)Since this is a question rather than an issue, I converted it to a GH discussion. | 
Beta Was this translation helpful? Give feedback.
                  
                    3 replies
                  
                
            
      Answer selected by
        ratcashdev
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
You can instantiate a new
Networkusing the external id:Since this is a question rather than an issue, I converted it to a GH discussion.