Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility issue with Docker Compose 2 #554

Merged
merged 1 commit into from
Jan 11, 2022

Conversation

ollietreend
Copy link
Contributor

The Docker Compose project has moved from v1 to v2.

For now, it's still possible to opt-out of v2 and revert to v1 when using Docker for Mac. However this option will likely go away at some point. It's therefore a good idea to ensure GOV.UK Docker works with both versions.

As far as I can see, the only compatibility issue that existed is that the nginx container attaches to the 'default' network. As I understand it, the network called default is no longer implicitly created with Docker Compose v2, so it needs to be defined in the docker compose file.

For more info, see: docker/compose#9015

It's not clear when this change happened as it's not documented as a known change: https://docs.docker.com/compose/compose-file/compose-versioning/

Demonstration of compatibility issue

The scripts bin/replicate-mysql.sh and bin/replicate-postgres.sh both run the command:

govuk-docker config

When running with Docker Compose v1, this command outputs a YAML document describing the current project config.

With Docker Compose v2, the command fails with an error:

$ govuk-docker config
docker-compose -f [...] config
service "nginx-proxy" refers to undefined network default: invalid compose project

However when the default network is explicitly defined in the main docker-compose.yml file, both v1 and v2 run correctly without error.

With this change applied, I'm now able to successfully run bin/replicate-mysql.sh and bin/replicate-postgres.sh regardless of the Docker Compose version I'm using.

The Docker Compose project has moved from v1 to v2.

For now, it's still possible to opt-out of v2 and revert to v1 when using Docker for Mac. However this option will likely go away at some point. It's therefore a good idea to ensure GOV.UK Docker works with both versions.

As far as I can see, the only compatibility issue that existed is that the `nginx` container attaches to the 'default' network. As I understand it, the network called `default` is no longer implicitly created with Docker Compose v2, so it needs to be defined in the docker compose file.

For more info, see: docker/compose#9015

It's not clear when this change happened as it's not documented as a known change: https://docs.docker.com/compose/compose-file/compose-versioning/
@ollietreend
Copy link
Contributor Author

This PR effectively makes the troubleshooting content added in #506 redundant – so I've removed it as part of this change.

Copy link
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried it locally with Content Publisher and it worked - nice job! ⭐

@ollietreend ollietreend merged commit e3958a7 into main Jan 11, 2022
@ollietreend ollietreend deleted the docker-compose-v2-compatibility branch January 11, 2022 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants