mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory
Hi!
I have a couple of questions:
The container I published earlier is giving an error. I tried simplifying and changing the Dockerfile, but nothing seems to change. The container builds and runs locally, the CI pipeline also passes correctly, but during deployment, it throws the following error: vbnet Copy code [Sep 23 12:23:36.956][ CYCLE COMPUTE] Console attached mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory chmod: missing operand after '755' Try 'chmod --help' for more information. [Sep 23 12:23:37.033][ CYCLE COMPUTE] Console disconnected (77.073087ms) [Sep 23 12:26:49.663][ CYCLE COMPUTE] Console attached mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory chmod: missing operand after '755' Try 'chmod --help' for more information. [Sep 23 12:26:49.794][ CYCLE COMPUTE] Console disconnected (130.256738ms) I even removed everything related to this from the Dockerfile (attached), but the issue persists.
FROM php:8.2-apache
Install necessary packages
RUN apt-get update && apt-get install -y libzip-dev zip unzip git && docker-php-ext-install zip
Enable Apache modules
RUN a2enmod rewrite RUN a2enmod ssl
Set Apache environment variables
ENV APACHE_RUN_USER=www-data ENV APACHE_RUN_GROUP=www-data
ENV APACHE_LOG_DIR=/var/log/apache2
ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid
ENV APACHE_RUN_DIR=/var/run/apache2
ENV APACHE_LOCK_DIR=/var/lock/apache2
# Create necessary directories
RUN mkdir -p $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
# Ensure Apache can access these directories
RUN chown -R www-data:www-data $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
RUN chmod 755 $APACHE_RUN_DIR $APACHE_LOCK_DIR $APACHE_LOG_DIR
Copy application files
COPY --chown=www-data:www-data ./app /var/www/html
Clean up
RUN rm -rf /var/lib/apt/lists/*
Set the working directory
WORKDIR /var/www/html
I created a second server in the Products cluster and increased the number of container instances to 2. The deployment happened, but both containers were placed on the same server. How can I ensure that containers are evenly distributed across servers? Afterward, I stopped the first server with the containers in the AWS console, but the containers didn’t automatically deploy on the second server. So, if the server crashes (not just the container), the application becomes unavailable. How can this issue be resolved?
Hey Ruslan!
Re:
How can I ensure that containers are evenly distributed across servers?
If the server nodes are in different data centers, this is best achieved using the high availability deployment strategy.
If server nodes are in the same data center, the edge deployment strategy will prioritize spreading the instances out. Edge does prioritize geographic distribution but it does not enforce it the same way that high availability does. Edge will also accept container deployments with just 1 instance while high availability requires 2.
For full control over each container instance's placement, use the manual deployment strategy. This strategy was originally designed for programmatic implementations where users wanted ultra granular control over distribution of instances.
The deployment strategy can be updated in the container configuration to manual but to change between deployment strategies other than specifically to manual, you'll need to recreate the container.
For the first issue you posted about the errors in console:
Re:
failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory chmod: missing operand after '755'
Can you share some more info on whats happening there during startup?
Thank you very much, Christopher!
The container was previously deployed successfully, but today, when trying to scale it to 2 containers, it throws an error and transitions to a "stopped" state. In this state, I cannot access the container console to see more detailed information. I reverted to deploying on just 1 container, but the error persists. The container deploys without any issues in the local environment using Docker Compose.
Hey Ruslan, thanks for providing that context.
When you were able to see this output from the console
[Sep 23 12:23:36.956][ CYCLE COMPUTE] Console attached mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory chmod: missing operand after '755' Try 'chmod --help' for more information. [Sep 23 12:23:37.033][ CYCLE COMPUTE] Console disconnected (77.073087ms) [Sep 23 12:26:49.663][ CYCLE COMPUTE] Console attached mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory chmod: missing operand after '755' Try 'chmod --help' for more information. [Sep 23 12:26:49.794][ CYCLE COMPUTE] Console disconnected (130.256738ms)
I believe you're saying that this error happens on start, but looking at your Dockerfile example it would seem that all you're trying to do is run a php apache process.
Is there any type of custom CMD or ENTRYPOINT being used during the startup of the server. If not, does your code do anything that would try to create or write to those directories?
Im just trying to better understand what process is causing those errors to happen.
This sounds similar to an issue my team encountered recently, where some of our containers failed to restart due to the following error:
Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
While this was for MySQL and not Apache, it's interesting that both errors relate to lock files on container restarts.
The issue we faced was discussed in this post: https://cycle.io/community/threads/66eda122747fbf121f86602a/issue-with-mysql-57-docker-containers-failing-to-restart
I don’t want to add confusion, but perhaps this could provide some insight for the Cycle team if the two issues are connected!
Hi! I don't think this issue could be related. I solved the issue by rebuilding under nginx. The container is up without errors now. I deployed it, assigned the DNS zone, but I'm seeing the error:
"unable to determine potential destinations: unable to connect to any instances of this container"
I've checked everything three times, restarted the services, deleted and redeployed, but the same error persists. The container worked perfectly fine locally, and now in Cycle, it also starts without errors and all the files are present.
Hi Ruslan,
Can you login to that container via SSH and run "netstat -aln"? My guess is that your nginx container is listening only on ipv4 where Cycle uses ipv6 between containers for communication. That error you're seeing is from the load balancer and 90% of the time, it's because of either a misconfigured port or the desired container is not listening on ipv6.
This page dives into it a bit more:
https://cycle.io/docs/platform/introduction-to-environments#ipv6-native-networks