Skip to content

Commit

Permalink
Fix network connect race with docker-compose
Browse files Browse the repository at this point in the history
Network connect/disconnect has to call the cni plugins when the network
namespace is already configured. This is the case for `ContainerStateRunning`
and `ContainerStateCreated`. This is important otherwise the network is
not attached to this network namespace and libpod will throw errors like
`network inspection mismatch...` This problem happened when using
`docker-compose up` in attached mode.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jun 11, 2021
1 parent dffbf16 commit 44d9c45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ func (c *Container) NetworkDisconnect(nameOrID, netName string, force bool) erro
}

c.newNetworkEvent(events.NetworkDisconnect, netName)
if c.state.State != define.ContainerStateRunning {
if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
return nil
}

Expand Down Expand Up @@ -1145,7 +1145,7 @@ func (c *Container) NetworkConnect(nameOrID, netName string, aliases []string) e
return err
}
c.newNetworkEvent(events.NetworkConnect, netName)
if c.state.State != define.ContainerStateRunning {
if !c.ensureState(define.ContainerStateRunning, define.ContainerStateCreated) {
return nil
}
if c.state.NetNS == nil {
Expand Down
2 changes: 2 additions & 0 deletions test/compose/test-compose
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ function test_port() {
fi
echo "# cat $WORKDIR/server.log:"
cat $WORKDIR/server.log
echo "# cat $logfile:"
cat $logfile
return
fi

Expand Down

0 comments on commit 44d9c45

Please sign in to comment.